For more information, see the instance code:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script type = "text/javascript">
Functionvalidation (){
Varval = document. getElementById ("txtNumber"). value;
Varregu =/^-[1-9] \ d * $ /;
If (val! = ""){
If (! Regu. test (val )){
Document. getElementById ("labResult"). style. color = "red ";
Document. getElementById ("labResult"). innerHTML = "verification failed! ";
} Else {
Document. getElementById ("labResult"). style. color = "green ";
Document. getElementById ("labResult"). innerHTML = "verification successful! ";
}
}
}
</Script>
</Head>
<Body>
<Input id = "txtNumber" name = "txtNumber" type = "text"/>
<Input id = "btnValidation" name = "btnValidation" type = "button" value = "verify" onclick = "validation ()"/>
Verification result: <label id = "labResult"> </label>
</Body>
</Html>
|
Portal
Use a JavaScript regular expression to verify non-positive integers:Http://www.111cn.net/wy/js-ajax/125202.htm
Validate a non-negative integer: http://www.111cn.net/wy/js-ajax/125206.htm using a JavaScript regular expression
Validate a non-zero positive integer: http://www.111cn.net/wy/js-ajax/125207.htm using a JavaScript regular expression