JS Verify age Name

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd ">

<meta http-equiv = "Content-type" content= "Text/html;charset=utf-8"/>

<script src= "Js.js" type= "Text/javascript" language= "JavaScript" >

</script>

<body>

<form>

Name: <input type = "text" id = "name" onblur = "checkname ();"/>

<span id = "S1" > Please enter 3-5 letters </SPAN><BR/>

Age: <input type = "text" id = "ages" onblur = "checkage ();" />

<span id = "S2" > Please enter 2 digits </span>

<input type = "submit" value = "submit" onclick = "return valid ();" />

</form>

</body>

Js.js

function CheckName () {var name = document.getElementById ("name"). Value;var S1 = document.getElementById ("S1"); var Regname =/^[a-za-z]{3,5}$/;///defines a RegExp object if (regname.test (name)) {//Use RegExp object method to verify s1.innerhtml = "input is correct"; S1.style.color = "Green";} else{s1.innerhtml = "typographical error"; S1.style.color = "Red";} return regname.test (name);} function Checkage () {var = document.getElementById ("Age"). Value;var s2 = document.getElementById ("s2"); var regname = /^\d{2}$/;if (Regname.test (age)) {s2.innerhtml = "entered correctly"; S2.style.color = "Green";} else{s2.innerhtml = "typographical error"; S2.style.color = "Red";} return regname.test (name);} function valid () {return checkname () && checkage ();}


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.