需要正则表达式 [英] Need Regular Expression

查看:118
本文介绍了需要正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要正则表达式,包括并允许以下条件。



-max。字符数:25个字符

-min。字符数:10个字符

- 只允许数字不是字母字符。[0-9]

-允许空格,括号,加号和减号



i需要正则表达式,允许这种格式

Need Regular Expression which include and allow below conditions.

-max. number of characters: 25 characters
-min. number of characters: 10 characters
-only allow numbers not alphabetic chars.[0-9]
-allow spaces, parentheses, plus and minus sign

i need regex which allow this type of format

推荐答案

Google给了我像http://regexlib.com/ [ ^ ],浏览那里







创建自己。检查这些

Expresso - 用于构建和测试正则表达式的工具 [ ^ ]

30分钟正则表达式教程 [ ^ ]
Google gave me sites like http://regexlib.com/[^], browse there

OR

Create yourself. Check these
Expresso - A Tool for Building and Testing Regular Expressions[^]
The 30 Minute Regex Tutorial[^]


对于你的问题,这个正则表达式会做:

For you question this regex will do:
^[0-9\+\- \(\)]{10,25}




但是!要检查电话号码肯定不好,因为它允许加号出现在任何地方,允许未闭合的括号...

因此,如果你想检查电话号码,你可以将它分成两个。一个用于正则表达式以检查输入中是否存在无效字符,另一个用于检查语法...


But! To check phone number it definitely not good, as it allows the plus sign to appear anywhere, allows unclosed parentheses...
So if you want to check phone numbers you may split it to two. One for a regex to check that no invalid char are in the input, and one other to check syntax...


这篇关于需要正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆