Regex to check if the first character is uppercase

前端 未结 5 1853
忘了有多久
忘了有多久 2021-02-13 13:37

I\'m trying to check that the first character of a username is capital, the following can be letters or numbers and at most 20 characters long. Can someone explain why my synta

5条回答
  •  误落风尘
    2021-02-13 14:33

    I would do it like this:

    var firstChar = strToCheck.substring(0, 1);
    
    if (firstChar == firstChar.toUpperCase()) {
        // it is capital :D
    }
    

提交回复
热议问题