Ann_M Posted December 13, 2003 Share Posted December 13, 2003 Hi, Im trying to create a constraint which will have a fixed length of 10. The constraint i have used is: CHAR(10)constraint Now according to the books "CHAR" should be a fixed length, in my terms a fixed length of 10, however, i have just tried to insert some values consisting of 9 characters and it was accepted. Do i need to add something to the constraint to allow the user to input exactly a fixed length of 10? Link to comment Share on other sites More sharing options...
Dave Posted December 13, 2003 Share Posted December 13, 2003 Hmm, I'm not sure about this, but I did a quick look on google for you: http://www.devguru.com/Technologies/jetsql/quickref/constraint.html This is Jet SQL so may be completely wrong, but apparently a constraint just limits what values you can put into your field, and perhaps reference other fields from different tables. Having not used it before, I'm not sure, but I don't think it's what you're after. Link to comment Share on other sites More sharing options...
fafalone Posted December 13, 2003 Share Posted December 13, 2003 Using a constraint like char[10] makes 10 the MAXIMUM, to set a minimum requirement you'll need to script a checker onto the page. Link to comment Share on other sites More sharing options...
Ann_M Posted December 14, 2003 Author Share Posted December 14, 2003 Using a constraint like char[10] makes 10 the MAXIMUM, i thougut varchar(2) sets a maximum length. So what kind oif script checker do i need to check the length? Link to comment Share on other sites More sharing options...
Sayonara Posted December 14, 2003 Share Posted December 14, 2003 Varchar(2) is the same as CHAR(2) as far as this example is concerned Like Faf says Ann, you need to validate the length of the string with a script before inserting it. if (strlen($THE_STRING) == 10) { // do the insert query } else { // send the user back to the form (or whatever) // add a warning message for good measure } Link to comment Share on other sites More sharing options...
Dave Posted December 14, 2003 Share Posted December 14, 2003 Just a simple one to check the string length. A simple piece of Javascript would do it. Link to comment Share on other sites More sharing options...
Sayonara Posted December 14, 2003 Share Posted December 14, 2003 This is such a small check that it would be better to do it server-side rather than client-side, and thereby reduce the threat to platform independence. Link to comment Share on other sites More sharing options...
Dave Posted December 14, 2003 Share Posted December 14, 2003 True, although sometimes it's more convenient to do a client-side check if it's only small and supported by most browsers. If you've got a big form for instance, then you don't want to have to re-insert all the information into your fields, and although this could be overcome with some more code on your server-side application, it's easier to write a couple lines of Javascript than 30 lines of php. Link to comment Share on other sites More sharing options...
Sayonara Posted December 14, 2003 Share Posted December 14, 2003 True, although it does depend how you parse the info. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now