The content of this article is about the various verification text box input formats implemented by js regular expressions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
cannot be empty
<input onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert('不能为空!')">
Only English and numbers can be entered
<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,'')">
The judgment characters are composed of letters and numbers, underscores, and periods. And the beginning can only be an underscore and a letter
/^([a-zA-z_]{1})([\w]*)$/g.test(str)
Only numbers can be entered
<input name="text" type="text" id="NewPage" onKeyUp="value=value.replace(/\D/g,'')" onafterpaste="value=value.replace(/\D/g,'')" >
Can only enter Chinese
<input type="text" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')">
Can only enter English
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')"> <input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">
Only Chinese, English, numbers, @ symbols and . symbols can be input
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,'')">
Only English input is allowed, and neither paste nor pop-up of the paste menu is allowed
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')" onkeydown="fncKeyStop(event)" onpaste="return false" oncontextmenu = "return false"/>
Only numbers and periods can be entered (note: the d in [^\d\.] cannot be written as a capital D, otherwise it will become all characters except numbers)
<input name="price" type="text" size="8" maxlength="8" onkeyup="value=value.replace(/[^\d\.]/g,'')" >
In short: first enter onkeyup="value=value.replace(/[^\X]/g,'')" in and then in (/[\X]/g, '') just replace the
##English: a-z, A-ZOther symbols@, dot or other symbols. You can also have multiple, just separate them with \.For example:
Chinese, English and numbers Add the @ symbol and the dot symbol: \a-\z\A-\Z0-9\u4E00-\u9FA5\@\.If you want to not be able to right-click the pop-up menu in the text box and paste the copied information If so, enter
onKeyDown="fncKeyStop(event)" onpaste="return false" oncontextmenu="return false;"
js regular expression verification time format example
The above is the detailed content of Various verification text box input formats implemented by js regular expressions. For more information, please follow other related articles on the PHP Chinese website!