如何使格式验证功能的输入文本与jQuery
问题描述:
我有形式这样如何使格式验证功能的输入文本与jQuery
<p>Masukan Posisi Baru</p>
<input type="text" id="nposisi"/></br>
<button id="ok">OK</button>
“确定”,然后单击功能我必须验证输入文本不是空的,并按照我的格式。
我的格式输入文本:
- 结合的字体和数字
- 有3-5字体
- 必须的资本字体
- 昏迷,不允许除点另一标点符号
ex:A2.8
空验证只是简单的
$(document).ready(function(){
$("#ok").click(function(){
var nposisi = $("#nposisi").val();
if(nposisi==""){
alert("Masukan dulu posisi baru");
exit();
}
});
});
,但我的问题,我在格式验证不知道?任何想法。感谢之前
答
使用正则表达式。
r = /^[\.A-Z0-9]{3,5}$/;
var nposisi = $("#nposisi").val();
if (nposisi.match(r)) {
alert("matches!");
} else {
alert("no match :(");
}
是什么'退出()'做什么? – undefined 2013-05-07 07:49:28
退出“if”函数 – andricoga 2013-05-07 07:50:17
那么,JavaScript中没有'exit'函数! JavaScript程序员使用'return [false]'。 – undefined 2013-05-07 07:50:47