Common javascript Functions _ javascript skills

Source: Internet
Author: User
Tags integer numbers
This article provides a summary of common centralized functions, which are very practical. For more information, see. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.