Regular Expression For At Least One Number

前端 未结 3 1633
野趣味
野趣味 2020-12-17 08:09

How would you create a regular expression for a value that should contain at least one number? The user can enter any special character, letter etc., but should contain at l

相关标签:
3条回答
  • 2020-12-17 08:43

    Try using this pattern

    .*[0-9].*
    

    For 6 to 20 use this

    ^(?=.*\d).{6,20}$ 
    
    0 讨论(0)
  • 2020-12-17 08:59

    You can use this pattern:

    /^(?=.{6,20}$)\D*\d/
    
    0 讨论(0)
  • 2020-12-17 09:08

    Use this Regex

    An easier solution would be to retain your existing regex, then create two new regexes to test for your "at least one alphabetic" and "at least one numeric".

    So, test for this :-

     /^([a-zA-Z0-9]+)$/
    

    Then this :-

     /\d{1}/
    

    Then this :-

     /[A-Z]{1}/i
    
    0 讨论(0)
提交回复
热议问题