开发者

Javascript Regular Expression

开发者 https://www.devze.com 2023-02-07 21:49 出处:网络
alert(/[a-zA-Z0-9 -_\\.,]+/.test(\'test_string@\'); I currently have the above code and I want to it to return false whenever something in the string doesn\'t match. For example, the string above ha
alert(/[a-zA-Z0-9 -_\.,]+/.test('test_string@');

I currently have the above code and I want to it to return false whenever something in the string doesn't match. For example, the string above has an @. The return would be true because test_string matches开发者_开发百科.

Is there a javascript function or some code that could help me with this?


There are beginning ^ and end $ of string matches:

/^[a-zA-Z0-9 \-_\.,]+$/.test('test_string@')
// ----------^ Also notice that escape! ;)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号