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!");
}
精彩评论