Giter Club home page Giter Club logo

js-regular-expression-awesome's Introduction

JS-Regular-expression-awesome

📄我收藏的正则表达式大全,欢迎补充

验证微信号

微信账号仅支持6-20个字母、数字、下划线或减号,以字母开头

/^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$/.test(value)

匹配腾讯QQ号码

[1-9][0-9]{4,}

JS替换字符串中的空格

var reg = /([^\s])\s+([^\s\b])/g;
var str = " **  北京   朝阳区  df "; 
str = str.replace(reg, "$1%$2")

匹配Email地址

[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?

匹配网址URL

[a-zA-z]+://[^\s]*

匹配(年-月-日)格式日期

([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))

匹配国内电话号码

\d{3}-\d{8}|\d{4}-\{7,8}

手机号码

带中划线的手机号码:/^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12})+$/

普通手机号码:/^1[34578]\d{9}$/

校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”

function isTel(s) { 
    var patrn=/^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false
    return true
}

配置中文字符

[\u4e00-\u9fa5]

匹配18位身份证

身份证号码最后一位目前只有X

/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/

匹配**邮政编码

[1-9]\d{5}(?!\d)

检查是否是IP地址

(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d).(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)

不允许输入如下字符: (像 !@#$%^&* 等)

var userName = $("#userRegistName").val(); 
var first = userName.charCodeAt(0); 
function CheckUserNameFormat(){
    if ((first>=65 && first <= 90)||(first>=97 && first <=122)){
    var pattern =/^[A-Za-z0-9_]+$/;  //首字母必须是A-Z或者a-z
    if(pattern.test(userName)){ 
         ......
    }
} 

匹配数字类型

//匹配正整数
^[1-9]\d*$
//匹配负数
^-[1-9]\d*$
//正数
^-?[1-9]\d*$
//匹配非负正数(正整数 + 0)
^[1-9]\d*|0$
//匹配非正负数(负整数 + 0)
^-[1-9]\d*|0$
//匹配正浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$
//匹配负浮点数
^-[1-9]\d*\.\d*|-0\.\d*[1-9]\d*$

js-regular-expression-awesome's People

Contributors

dunizb avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.