Regular Expression related: first character alphabet second onwards alphanumeric+some special characters

前端 未结 3 1681
無奈伤痛
無奈伤痛 2021-02-06 03:46

I have one question related with regular expression. In my case, I have to make sure that first letter is alphabet, second onwards it can be any alphanumeric + some special char

3条回答
  •  天命终不由人
    2021-02-06 03:56

    I think the simplest answer is to pick and match only the first character with regex.

    String str = "s12353467457458";
    if ((""+str.charAt(0)).matches("^[a-zA-Z]")){
        System.out.println("Valid");
    }
    

提交回复
热议问题