JavaScript alphabet and digital double-precision digital verification

Source: Internet
Author: User

Three pages special effects letters and digital double-precision digital Verification Oh, you can enter the number of legitimacy verification, the last side of an example to illustrate.

Verify the range of the number size

function Check_num_value (obj_name,obj,minvalue,maxvalue) {
var reg =/^[0-9]+$/;
if (obj.value!= "" &&!reg.test (Obj.value)) {
Alert (obj_name+ ' can only enter numbers!) ');
Obj.value = "";
Obj.focus ();
return false;
}else if (minvalue>obj.value| | Obj.value>maxvalue) {
The scope of alert (obj_name+) is "+minvalue+"-"+maxvalue+");
Obj.value= "";
Obj.focus ();
return false;
}

}

Verification can only be letters and numbers

function Checkzmornum (zmnum) {
var zmnumreg=/^[0-9a-za-z]*$/;
if (zmnum.value!= "" &&!zmnumreg.test (Zmnum.value)) {
Alert ("Only enter letters or numbers, please re-enter http://www.111cn.net");
Zmnum.value= "";
Zmnum.focus ();
return false;
}
}

Verifying double digits

function Check_double (obj,obj_name) {
var reg =/^[0-9]+ (. [ 0-9]+)? $/;
if (obj.value!= "" &&!reg.test (Obj.value)) {
Alert (obj_name+ ' must be filled with a valid double number ');
Obj.value = "";
Obj.focus ();
return false;
}
}

Let's look at a simple example

<form name=form1 target= "_blank" method=post onsubmit= "return Dosubmit (This)"
Member number (6 digits): & Lt;input type=text name=mem_id>
<input type=submit name=submit1 value= "Submit"
</form>
< Script language= "javascript"
function Dosubmit (frm)
{
if (frm.mem_id.value.length!= 6)
{
Alert ( "Membership number must be 6");
return false;
}
Else
{
var mem_value = Frm.mem_id.value;
for (Var i=0; i<mem_value.length; i++)
{
if (mem _value.charat (i) < ' 0 ' | | Mem_value.charat (i) > ' 9 ')
{
Alert ("member numbers can only be numeric Http://www.111cn.net");
return false;
}
}
}
Frm.submit ();
return true;
}
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.