js check input text box input

js various authentication format input text box (regular expressions)
can not be empty 
<input onblur = "if (this.value.replace (/ ^ + | + $ / g, '') == '') alert ( ' not is empty! ') ">

只能输入英文和数字
<input onblur="if(/[^0-9a-zA-Z]/g.test(value))alert('有错')">
<input onkeyup="value=value.replace(/[^0-9a-zA-Z]/g,'')"/>
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')">

Determine the character of letters and numbers, underscores, number of points. And the beginning of the letter can only be underlined and 
/^([a-zA-z_]{1})([\w]*)$/g.test(str )

只能输入数字
<input name="text" type="text" id="NewPage" onKeyUp="value=value.replace(/\D/g,'')" onafterpaste="value=value.replace(/\D/g,'')" >

Only enter Chinese
<input type = "text" onkeyup = "value = value.replace (/ [^ \ u4E00- \ u9FA5] / g, '')">

只能输入英文
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')">
<input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">

Can input Chinese, English, numbers, and symbols @ symbol
<input type = "text" onkeyup = "value = value.replace (/ [^ \ a- \ z \ A- \ Z0-9 \ u4E00- \ u9FA5 \ @ \.] / g, '') ">

English input only, and fails to be ejected can not paste Paste menu
<input type = "text" onkeyup = "value = value.replace (/ [^ \ a- \ z \ A- \ Z] / g, '')" onkeydown = "fncKeyStop (event)" onpaste = "return false" oncontextmenu = "return false" />

Only enter numbers and periods (Note: d in [. ^ \ D \] can not be written in uppercase D, otherwise it becomes all the characters except digits)
<the INPUT name = ". Price" of the type = "text" size = "8" maxlength = "8 " onkeyup = "value = value.replace (/ [^ \ d \.] / g, '')">

In short: the first input onkeyup <input> li = "value = value.replace (/ [^ \ X] / g, '')" and then (/ [\ X] / g, 'X') was replaced enter the code you want on it

Chinese: u4E00-u9FA5
numbers: d, 0-9
English: AZ, AZ
. Other symbols @, dots or other symbols may be a plurality, with \ spaced apart on the line.
For example:
in alphanumeric symbols add the @ sign : \ a- \ z \ A- \ Z0-9 \ u4E00- \ u9FA5 \ @ \.

To pop-up menu and the right information can not paste the copied text into the box, then will enter onKeyDown = "fncKeyStop (event)" onpaste = "return false" oncontextmenu = the <input> in "return false;"

Guess you like

Origin blog.csdn.net/yijiupingfan0914/article/details/93741437