Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted
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?

Posted

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
}

Posted

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.

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.