regex - Regular expression with 6 characters in ASP.NET -


i need regular expression in asp.net accept 6 characters ,

  1. at second position should accept underscore (_) and
  2. at third position should accept maybe underscore (_) or hash (#) and
  3. at fourth position should accept hash (#).

note: in regex user can enter: number, alphabets or star (*) @ position instead of above mentioned positions.

can 1 me out on this?

like:

  1. a__cde
  2. ab##cd
  3. a_#cde
  4. ******
  5. abcdef
  6. 123456

try following expression:

(?i)^(?=^(?:[a-z0-9*]*(?:#{1,2}|_{1,2})[a-z0-9*]*|[a-z0-9*]*)$).{6}$ 

will match:

  • a__cde
  • ab##cd
  • ******
  • abcdef
  • 123456

won't match:

  • a_#cde
  • a_##aa
  • a__#bc
  • _##*

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -