gpt4 book ai didi

java - 手机号码验证问题的正则表达式模式

转载 作者:行者123 更新时间:2023-12-02 01:55:43 25 4
gpt4 key购买 nike

我不知道我的代码有什么问题,我只想接受这种格式的手机号码:09xxxxxxxxx(始终以“09”开头,总共 11 位数字)。所有努力将不胜感激。提前致谢。

Here is the picture of the problem

代码如下:

String a2= jTextField6.getText();
String a3 = jTextField7.getText();

Pattern p = Pattern.compile("^(09) \\d {9}$");
Matcher m = p.matcher(jTextField5.getText());

if (!m.matches()){
int b = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog(this, "Invalid Mobile Number", "Error", b);
return;
}
if (null==a2||a2.trim().isEmpty()){
int b = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog(this, "Fields should not left blank", "Error", b);
return;
}
if(a3==null||a3.trim().isEmpty()){
int b = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog(this, "Fields should not left blank", "Error", b);
}

else {
int c = JOptionPane.YES_NO_OPTION;
int d = JOptionPane.showConfirmDialog(this, "Confirm Purchase?","Costume 1", c);
if (d==0){
JOptionPane.showMessageDialog( null,"Your costume will be delivered 3-5 working days." +"\n"+"\n"+" Thank You!");
}

最佳答案

您必须删除正则表达式中的空格:

 Pattern p = Pattern.compile("^(09)\\d{9}$");

否则它们将被视为必须存在的角色。

关于java - 手机号码验证问题的正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52345158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com