1. Input can only enter integer numbers and letters
$ (document). On (' KeyUp ', ' #no ', function () {
var val = $.trim ($ (this). Val ());
if (val = = NULL | | val = = ") return
;
$ (this). Val (Val.replace (/[^0-9a-z]+/ig, ')); Can only enter integer numbers and Letters
});
Many other implementations that come out of Baidu are problematic. They do not accurately represent "only numbers and letters" because they enter punctuation in advance, such as allowing a decimal point to be entered. and other symbols. For example, the following is a Baidu out of the answer:
Value=value.replace (/[^\w\.\/]/ig, ')
value=value.replace (/[^\d|chun]/g, ')
Value=value.replace (/[^\w \.\/]/ig, "")
The 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 empty");
$ (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 a string
$ (function () {
var a = ' testabc,. 、,./Rice Cooker 123def ';
b = A.replace (/[^0-9]+/ig, "");
alert (b);
b = A.replace (/[^a-z]+/ig, "");
alert (b);
});
4. jquery Cookie Plugin Usage
var Isfs = $ (this). attr ("Datas");
$.cookie ("Isfs", isfs,{expires:7});
The above mentioned is the entire content of this article, I hope you can enjoy.