Problem with Maxlength validation of jquery
I am using the maxlength function of jquery.validate.js plugin to validate for mobile number. as following
txtMobileNo: {
number : true,
minlength: 10,
maxlength: 12
},
and in mysq开发者_如何学JAVAl description of this field is as following...
mobile_no int(11)
when i enter any valid mobile number it store only this value "2147483647"..
It doesn't sound like the problem is with your validation, but rather your actual code to store a value in the database. Remove the jQuery validation. Try it again. I bet you still get the same error.
2147483647 is the maximum value of a 32-bit signed integer. If you're trying to store 10-12 digit long mobile numbers in a 32-bit signed integer field, you're almost always going to overflow.
You should almost certainly use varchar(12) or something like that for your database representation.
I agree with @Carson63000, although a phone number is made of numbers, it has no numeric value (for example, try storing a number that starts with a 0), so you should hold the number with its string representation, more specifically, varchar or even char if they have a fixed length.
精彩评论