作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个注册表单,其中有一个 MobileNo 字段,用户应该在其中提供他们的手机号码,但该字段是可选的,因为用户可以选择不提供他/她的手机号码。
在数据库表中,我保留了该字段的ALLOW NULL
选项。
现在我想在此字段上使用 JavaScript 验证,以便用户只能输入一个整数值,并且只有 10 位数字(如果他/她选择提供他/她的手机号码)。
问题是,当我为此编写代码时,当我将移动字段保留为空时,它会在 JavaScript 验证正在处理时显示错误。
我的 JavaScript 代码如下:
function f1() {
if (document.form2.mobile.length!=10 || isNan(document.form2.mobile) {
alert("Mobile No must be NUMERIC and 10 digit long");
return false;
}
是否有任何解决方案,因为这些验证仅在用户选择输入他/她的手机时才有效,否则如果为空,注册将完成。
最佳答案
将其包装在另一种情况下,如下所示:
function f1() {
if(document.form2.mobile.value !== "") {
if (document.form2.mobile.length!=10 || isNan(document.form2.mobile)
{
alert("Mobile No must be NUMERIC and 10 digit long");
return false;
}
}
}
关于可选移动端的 JavaScript 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22539128/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!