新加坡邮政编码或邮政编码确认 [英] singapore ZIPCODE or Postal code VALIDATION
本文介绍了新加坡邮政编码或邮政编码确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想验证以确保用户输入新加坡邮政编码。
我可以知道如何开始吗?
解决方案
你可以从这里开始:
正则表达式 [ ^ ]
..这里是基本语法参考 [ ^ ]
编写符合格式的正则表达式并应用它。
< blockquote>
< html >
< head >
< script type = text / javascript >
函数PinVerify()
{
var strtext = document.getElementById(textbox)。value;
var index = strtext.length;
//document.write(index);
if(index == 6)
{
///document.write(\"1111111);
if(strtext.charCodeAt(0)== 48)
{
//document.write(\"222222);
alert(ZIP不能从零开始);
}
其他
{
//document.write(\"222211111);
for(var i = 1; i < index; i ++)
{
// document.write(22222sdsdsd2);
< span class =code-attribute> var < span class =code-attribute> asciiValue = strtext.charCodeAt(i);
if(asciiValue > = 48&& asciiValue < = 57)
< span class =code-attribute> {
< span class =code-attribute>
// document.write(22222256565656 );
< span class =code-attribute> alert(Pin 正确 );
}
else
< span class =code-attribute> < span class =code-attribute> {
alert(仅 数字 允许 中的代码属性> Zip 代码);
< span class =code-attribute> }
}
< span class =code-attribute> }
}
else
{
alert(Pin code length 可以 不 less 比 六);
< span class =code-attribute> }
}
< / script >
< / head >
< 正文 >
输入任意内容值:< 输入 类型 = text id = textbox / >
< 按钮 onClick = PinVerify() > 检查邮政编码< / button >
< < span class =code-leadattribute> / body >
< / html >
HI, i wan to validate to make sure the user enter Singapore zipcode.
May i know how to start?
解决方案
You can start from here:
Regular-Expressions[^]
..and here is Basic Syntax Reference[^]
Write a regex that conforms to the format, and apply it.
<html> <head> <script type="text/javascript"> function PinVerify() { var strtext=document.getElementById("textbox").value; var index=strtext.length; //document.write(index); if(index==6) { ///document.write("1111111"); if(strtext.charCodeAt(0)==48) { //document.write("222222"); alert("ZIP Cannot start from zero"); } else { //document.write("222211111"); for(var i=1;i<index;i++) { //document.write("22222sdsdsd2"); var asciiValue=strtext.charCodeAt(i); if(asciiValue>=48&&asciiValue<=57) { //document.write("22222256565656"); alert("Pin is Correct "); } else { alert("Only Numbers is allowed in Zip Code"); } } } } else { alert("Pin code length can not be less than six"); } } </script> </head> <body> Enter any value:<input type="text" id="textbox" /> <button onClick="PinVerify()">Check For Zip Code</button> </body> </html>
这篇关于新加坡邮政编码或邮政编码确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文