jquery的Maxlength验证问题
我正在使用 jquery.validate.js 插件的 maxlength 函数来验证手机号码。如下
txtMobileNo: {
number : true,
minlength: 10,
maxlength: 12
},
并且在 mysql 中该字段的描述如下...
mobile_no int(11)
当我输入任何有效的手机号码时,它仅存储此值“2147483647”..
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 mysql description of this field is as following...
mobile_no int(11)
when i enter any valid mobile number it store only this value "2147483647"..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意@Carson63000,虽然电话号码是由数字组成的,但它没有数值(例如,尝试存储以0开头的数字),因此您应该用其字符串表示形式保存该数字,更具体地说,varchar甚至是 char(如果它们具有固定长度)。
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.
听起来问题不在于您的验证,而在于您在数据库中存储值的实际代码。删除 jQuery 验证。再试一次。我打赌你仍然会遇到同样的错误。
2147483647 是 32 位有符号整数的最大值。如果您尝试在 32 位有符号整数字段中存储 10-12 位长的手机号码,则几乎总是会溢出。
您几乎肯定应该使用 varchar(12) 或类似的东西来表示您的数据库。
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.