Summary of common javascript Functions and summary of javascript
1. input can only be an integer and a letter
$ (Document ). on ('keyup', '# no', function () {var val = $. trim ($ (this ). val (); if (val = null | val = '') return; $ (this ). val (val. replace (/[^ 0-9a-z] +/ig, ''); // only integer numbers and letters can be entered });
There are problems with many other implementations of baidu. They cannot accurately represent "only numbers and letters can be entered", because they pre-enter punctuation marks, such as allowed to enter decimal points. For example, the answer from Baidu is as follows:
value=value.replace(/[^\w\.\/]/ig,'')value=value.replace(/[^\d|chun]/g,'')value=value.replace(/[^\w\.\/]/ig,'')
The above answers are all problematic.
2. email format Verification
Function validate_email (myThis) {var val = $. trim ($ (myThis ). val (); if (val = null | val = "") {$ ("# email_error "). text ("email cannot be blank"); $ (myThis ). focus (); return;} if (val! = Null & val! = "") {If (! /^ [A-zA-Z0-9 _-] + @ [a-zA-Z0-9 _-] + (\. [a-zA-Z0-9 _-] +) + $/g. test (val) {$ ("# email_error "). text ("email format error"); $ (myThis ). focus (); return ;}$ ("# email_error "). text ("");}
3. Extract integer numbers and English letters from strings
$ (Function () {var a = 'testabc ,. ,,. /Rice cooker 123def '; B =. replace (/[^ 0-9] +/ig, ""); alert (B); B =. replace (/[^ a-z] +/ig, ""); alert (B );});
4. Use the jquery cookie plug-in
var isFs = $(this).attr("datas"); $.cookie("isFs",isFs,{ expires: 7 });
The above is all the content of this article. I hope you will like it.