简体   繁体   English

Javascript通过正则表达式在字符串中找到模式

[英]Javascript find a pattern in a string through regex

I have one string i want to check that wether that string has number or not , that string can contain the alphabets or mobile number with country code . 我有一个字符串,我想检查一下该字符串是否包含数字,该字符串可以包含带有国家代码的字母或手机号码。 So i want to detect that does it has mobile number ( which can have + or '0' and integers ) . 所以我想检测它是否具有手机号码(可以有+或'0'和整数)。

I tried using this [0-9] but i couldnt able to make the pattern for it . 我尝试使用此[0-9],但我无法为其制作图案。

thanks 谢谢

Is this string coming from a form input? 此字符串是否来自表单输入? If so, there's a jQuery library for that called Masked Input . 如果是这样,那么有一个jQuery库称为Masked Input

If it's coming from a set variable that you want validated internally, you'll want to look here . 如果它来自要在内部进行验证的set变量,则需要在此处查看

Hope this helps. 希望这可以帮助。

Got the solution 得到了解决方案

 \b[0-9+]+\b

Tested here 在这里测试

http://www.regular-expressions.info/javascriptexample.html http://www.regular-expressions.info/javascriptexample.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM