skip to Main Content

regex expression which contains 9 atleast alphabets and 1 digits and the position of alphabets and digit can be anywhere.

eg-

rahulkumar1
rahul9kumar
1RahulKumar

/[A-Za-z]{9,}[0-9]{0,1}/  

I have tried using this but it does not worked out.enter image description here

3

Answers


  1. If you only want to allow chars a-z A-Z or digits:

    ^(?=[a-zA-Z]*d)(?:d*[a-zA-Z]){9}[a-zA-Zd]*$
    

    Explanation

    • ^ Start of string
    • (?=[a-zA-Z]*d) Assert at least a single digit
    • (?:d*[a-zA-Z]){9} Match at least 9 times a char a-zA-Z preceded by optional digits
    • [a-zA-Zd]* Match optional chars a-z A-Z or digit
    • $ End of string

    Regex demo

    Login or Signup to reply.
  2. The following matched the requirements, I don’t know if it generally valid as you only gave three examples:

    [a-zA-Z]*[d]{1}[a-zA-Z]*

    Login or Signup to reply.
  3. Does this work (JS):

    let a = "abcedf123.f4ada";
    let b = [...a.matchAll(/[a-zA-Zd]{9,}/g)];
    console.log(b);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search