Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须根据以下条件验证电话号码,
It should only take numeric values. Minimum 10 and Maximum 15
如何在满足上述要求的java中编写正则表达式?我是正则表达式的新手。
试试正则表达式
^\\d{10,15}$
这\d是数字量词的预定义字符类,表示重复上一个模式的 10 到 15 次 {10, 15}
\d
{10, 15}
前任:
String input = "1234567890"; Pattern pattern = Pattern.compile("^\\d{10,15}$"); if (pattern.matcher(input).find()) { System.out.println("Valid"); }
使用这个正则表达式:
\\d{10,15}
\d匹配一个数字(前面的 \ 用于转义)
{10,15}允许最少 10 次和最多 15 次出现前面的模式
{10,15}
\d 代表数字 0-9
(\d){10,15}