jquery的Maxlength验证问题

发布于 2024-09-12 06:26:55 字数 294 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆消瘦 2024-09-19 06:26:56

我同意@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.

为你鎻心 2024-09-19 06:26:55

听起来问题不在于您的验证,而在于您在数据库中存储值的实际代码。删除 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文