开发者

how to use regular expression for validation of String must begin with letter, all other characters can be letter/number/space in java

I am doing validation of String 开发者_运维问答which contains ASAHSHAS,342746726,GHG55656 this valid String and spaces are allowed. Thanks In advance!!


This should do it.

^[a-zA-Z][a-zA-Z0-9 ]+$


The regular expression that you are looking for may look like this ^\\w[\\w\\d ,]*$. This is an example using it:

String string = "ASAHSHAS,342746726,GHG55656";
if (string.matches("^\\w[\\w\\d ,]*$")) {
    System.out.println("It matches!");
}
else {
    System.out.println("It does NOT match!");
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜