xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js regular expression & email checker

js regular expression & email checker


const isValidEmail = (email = ``) => /^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email);

function isValidEmail(email = ``) {
    return /^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email);
}

test


email = `wwW@com.xyz`;
"wwW@com.xyz"
/^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email)
true
email = `ww.W@com.xyz.abc`;
"ww.W@com.xyz.abc"
/^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email)
true
email = `ww.W@@com.xyz.abc`;
"ww.W@@com.xyz.abc"
/^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email)
false
email = `ww.W@com.xyz.abc..ufo`;
"ww.W@com.xyz.abc..ufo"
/^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email)
false
email = `ww.W@com.xyz.abc.nba.ufo`;
"ww.W@com.xyz.abc.nba.ufo"
/^([\w+\.])+@(\w+)([.]\w+)+$/ig.test(email)
true

Regular Expressions & Cheatsheet

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Character_classes

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes

\w & \W

基本的拉丁字母,包括下划线

\w === [A-Za-z0-9_]

\W === [^A-Za-z0-9_]

\d & \D

阿拉伯数字

\d === [0-9]

\D === [^0-9]

\s & \S

匹配单个空格字符,包括空格,制表符,换页符,换行符和其他Unicode空格。

\s === [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]

\S === [^A-Za-z0-9_]

\b & \B

边界字符检测

// 前,后
\b 

// 前,后
\B 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Assertions

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions

Group

分组


Range

范围


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Groups_and_ranges

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges

Quantifiers

量词


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Quantifiers

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Quantifiers

refs

https://regexper.com/

Regular Expression

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet

https://www.nowcoder.com/ta/front-end



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-08-25 11:37  xgqfrms  阅读(313)  评论(2编辑  收藏  举报