Javascript special value text box input verification

Source: Internet
Author: User
<! -- Only numerical values are allowed. -->
< Public: attach event = " Onpaste " Onevent = " Checkpaste () "   / >
< Public: attach event = " Onkeypress " Onevent = " Checkinput () "   / >
< Public: attach event = " Onfocus " Onevent = " Getfocus () "   / >
< Public: attach event = " Onblur " Onevent = " Lostfocus () "   / >
< Script Language = " Javascript " >
Function Checkinput (){
VaR K = Event. keycode;
Switch (Element. classname ){
Case   " Integeronly " :
/*
Only numbers and decimal places are allowed. Otherwise, disableinput
13 is a response
*/
If (K <   48 | K >   57 ) && K ! =   13 ){
Disableinput ();
}
Break ;
Case   " Decimalonly " :
/*
Only numbers are allowed. Otherwise, disableinput
13 is a response
46 is the decimal point
*/
If (K <   48 | K >   57 ) && K ! =   13 && K ! =   46 ){
Disableinput ();
}
Break ;
Case   " Usercode " :
/*
Only English letters, underscores, and numbers are allowed. Otherwise, disableinput
13 is a response
46 is the decimal point
*/
If (K <   97 | K >   122 ) // Lowercase letters
&& (K <   65 | K >   90 ) // Uppercase letters
&& (K <   48 | K >   57 ) // Number
&& K ! =   13 ){ // Return row
Disableinput ();
}
Break ;
}
}
/*
* Events triggered during pasting
* The called filtrateinput is in resume. aspx.
* Abandoned
  */
Function Checkpaste (){
Return   False ;
Ctrlid = Element. ID;
SetTimeout ( " Filtrateinput (\" " + Ctrlid + " \") " , 1 );
}
Function Disableinput (){
If (Element. classname =   " Integeronly "
| Element. classname =   " Decimalonly "
| Element. classname =   " Usercode " )
Event. returnvalue =   False ;
}
Function Getfocus (){
If (Element. Type =   " Text "  
| Element. Type =   " Password "
| Element. Type =   " Textarea " )
{
If ( ! (Element. readonly )){
Element. style. backgroundcolor =   " # Dcf1fa " ;
}
}
}
Function Lostfocus (){
If (Element. Type =   " Text "  
| Element. Type =   " Password "
| Element. Type =   " Textarea " )
{
Element. style. backgroundcolor =   "" ;
}
}
< / 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.