Home  >  Article  >  Web Front-end  >  js limit number js limit input implementation code_javascript skills

js limit number js limit input implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:47:281289browse
1. Only Chinese characters can be input
Copy code The code is as follows:



2. Only numbers can be entered
Copy code The code is as follows:



Simple prohibition of inputting Chinese characters
Copy code The code is as follows:



Enter numbers and decimal points:
Copy code The code is as follows:

onkeyup="value=value.replace(/[^d{1,}.d{1,}|d{1,}]/g,'')"

javascript can only enter numbers and ":".2007-11-24 15:50
Only numbers and ":" can be used, for example, when entering time.
Copy code The code is as follows:



Only letters and equal signs can be entered, but Chinese characters cannot be entered.

Other things:
Script javascript that can only enter numbers- -
Copy code The code is as follows:



The first half of the sentence means that keyboard typing can only be numbers, and the second half of the sentence means that pasting can only be numbers
Copy code The code is as follows:




3. JavaScript limits only numbers and English to be entered
Copy code The code is as follows:

function isregname( checkobj)
{
var checkOK = "0123456789 -_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var checkStr = checkobj;
var allValid = true;
var decPoints = 0;
for (i = 0; i < checkStr.length; i )
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j )
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
return (allValid)
}
----------------
if(!(isregname(obj.loginname.value))){
alert("[Member code] does not comply with the specification, member code It can only be English letters or numbers");
obj.loginname.focus();
return(false);
}
if(!(isregname(obj.password.value))) {
alert("[Password] does not meet the specifications, the password can only be English letters or numbers");
obj.password.focus();
return(false);
}

4.javascript can only input English and numbers into the input box
Copy code The code is as follows:



5. You can use Javascript to check the text box and filter out non-0-9 characters
Copy code The code is as follows:

[url=http://blog.csdn.net/xujh/admin/EditPosts.aspx] [/url]

6. Only the IP address format can be entered in the text box
Copy code The code is as follows:






<script> <br>function mask(obj ){ <br>obj.value=obj.value.replace(/[^d]/g,'') <br>key1=event.keyCode <br>if (key1==37 || key1==39) <br>{ obj.blur(); <br>nextip=parseInt(obj.name.substr(2,1)) <br>nextip=key1==37?nextip-1:nextip 1; <br>nextip= nextip>=5?1:nextip <br>nextip=nextip<=0?4:nextip <BR>eval("ip" nextip ".focus()") <BR>} <BR>if(obj.value. length>=3) <br>if(parseInt(obj.value)>=256 || parseInt(obj.value)<=0) <BR>{ <BR>alert(parseInt(obj.value) "IP Wrong address! ") <BR>obj.value="" <BR>obj.focus() <BR>return false; <BR>} <BR>else <BR>{ obj.blur(); <BR>nextip=parseInt( obj.name.substr(2,1)) 1 <BR>nextip=nextip>=5?1:nextip <br>nextip=nextip<=0?4:nextip <BR>eval("ip" nextip ".focus ()") <BR>} <BR>} <BR>function mask_c(obj) <BR>{ <BR>clipboardData.setData('text',clipboardData.getData('text').replace(/[^d ]/g,'')) <BR>} <BR></script>
IP address input

IP address input

.
.
.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn