检查整数 JavaScript 是否形成
Checking if integer JavaScript forms
我已经开始学习javascript,我无法获得表单的安全代码部分(并且我尚未修复其他内容,例如卡号)以发出警报,如果他们没有输入3个整数,我可以让它发出警报,如果该人没有输入3个整数/字符串/符号等......但是>或<3。但是,如果他们传递的东西不是整数,我无法让它提醒用户。谢谢!。
编辑:所以我试图解决的问题是如何在 Form.cvs.value 上运行我的 is_int 函数我很抱歉,如果我不清楚它有点混乱。
<script type="text/JavaScript">
function is_int(value){
if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
return true;
} else {
return false;
}
};
function verification(theForm) {
content = "";
var cardLen = (theForm.cardLength.value).length;
var securitycode = new is_int(theForm.cvs.value);
if (cardLen !== 16) {
content += "Please make sure you've entered 16 digits.";
}
if ((theForm.userName.value).length === 0) {
content += "Please make sure you've entered the correct name.";
}
if ((theForm.month.value) < 1 || theForm.month.value > 12 || theForm.month.value === "" || theForm.month.value === "MM") {
content += "Please make sure the you've entered the correct month.";
}
if ((theForm.year.value) < 2016 || ((theForm.year.value) === "" )) {
content += "Please make sure you've entered the correct expiry year.";
}
if ( !securitycode || ( (theForm.cvs.value).length !== 3) ) {
content += "Please make sure you've entered the correct security code.";
}
if (!content == "") {
alert (content); return false;
}
};
</script>
</head>
<body>
<br>
<br>
<br>
<center><h1>Checkout:</h1></center>
<div style="position:absolute; left:600px; top:200px;">
<form name="myForm" class="theForm" onSubmit="return verification(this)" >
Card Number: Expiration:
<br>
<input type="text" name="cardLength"> <input type="text" name="month" style="width:30px" value="MM"> - <input type="text" name="year" style="width:30px" value="YY">
<br>
Name: Security Code:
<br>
<input type="text" name="userName"> <input type="text" name="cvs" style="width:30px">
<br>
<br>
<input type="submit" value="Submit">
</form>
</div>
您不想创建new
is_int
。New 创建一个对象的实例并调用其构造函数,但您只需要从函数中获取返回值。
if ( !is_int(theForm.cvs.value) || theForm.cvs.value.length !== 3 ) {
content += "Please make sure you've entered the correct security code.";
}
相关文章:
- 是否可以控制获取哪些Google地图脚本(JavaScript API)
- 用于检查数组中是否存在元素的javascript自定义方法
- 是否可以在浏览器中使用纯JavaScript保存音频流
- 是否可以使用JavaScript/AAJAX在客户端创建一个文件
- 我是否可以检测到javascript正在被卸载(作为调试模式)
- PhantomJS - 检查javascript函数是否正在运行的任何方法
- 是否有任何JavaScript UI组件可以显示字符串之间的差异
- javascript跨浏览器确定用户是否滚动到页面底部
- 是否可以用JavaScript显示等效的文件夹对话框
- 检查是否存在使用chrome扩展的javascript库
- 如何知道javascript for语句中的所有结果是否都是错误的
- 是否存在Javascript Liferay Service库的文档?如何处理错误情况
- 是否可以使用jquery或javascript将自动增量类添加到列表中
- javascript移动交叉浏览器确定用户是否滚动到页面底部
- 有没有一种方法可以从Javascript检测特定的应用程序是否安装在(AndroidiOS)设备上
- javascript数组元素是否知道其封闭数组
- 是否“;对于的“;循环迭代遵循JavaScript中的数组顺序
- 是否有任何设置阻止JavaScript在系统上工作
- 是否可以在javascript中读取IE中的本地文件
- 是否有任何Javascript函数从指定的索引中进行正则表达式匹配