1 Star 0 Fork 54

chamrain/StudyStudio

forked from JoyPoint/StudyStudio 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
forms_check.js 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
JoyPoint 提交于 2019-10-07 16:08 +08:00 . WebCode v1.0
// forms_check.js
// A function tst_phone_num is defined and tested.
// This function checks the validity of phone
// number input from a form
// Function tst_phone_num
// Parameter: A string
// Result: Returns true if the parameter has the form of a valid
// seven-digit phone number (3 digits, a dash, 4 digits)
function tst_phone_num(num) {
// Use a simple pattern to check the number of digits and the dash
var ok = num.search(/^\d{3}-\d{4}$/);
if (ok == 0)
return true;
else
return false;
} // end of function tst_phone_num
// A script to test tst_phone_num
var tst = tst_phone_num("444-5432");
if (tst)
document.write("444-5432 is a valid phone number <br />");
else
document.write("Program error <br />");
tst = tst_phone_num("444-r432");
if (tst)
document.write("Program error <br />");
else
document.write("444-r432 is not a valid phone number <br />");
tst = tst_phone_num("44-1234");
if (tst)
document.write("Program error <br />");
else
document.write("44-1234 is not a valid phone number <br /");
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chamrain/StudyStudio.git
git@gitee.com:chamrain/StudyStudio.git
chamrain
StudyStudio
StudyStudio
master

搜索帮助