Search code examples
regexregular-language

Regular Expression UserName maker


I am creating a user login page in which user can input his/her name as below: username must start with alphabet as minimum 5 to 30 times, can also be 5 to 10 times, 5 to 23 times but the maximum must be under 30 characters count THEN follow or not follow by [0-9] digits 1 to 10 times, digit can also be 1 to 5 times or 1 to 9 times but the maximum number must be under 10 digits count.

Sample:

  1. dksdfekpwef
  2. askdkindolsiiejd12324434
  3. kksdq9

Thank you very much for your help.


Solution

  • The following regex would do it ...

    [a-zA-Z]{5,30}\d{0,10}
    

    see regex demo / explanation