-1

i have this expression to allow numbers and uppercase and lowercase letters and i also need to allow characters like - (minus) and _ (underline) and no white spaces can anyone help me with this please

if(txt1_len == 0 || txt1_len > 16 || txt1_len < 16 || !text1.value.match(
/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-z\d]*$/))

the characters - and _ must not be mandatory but can be accepted. whitespace must not be accepted at all

thank you

kimfarid
  • 3
  • 2
  • 1
    Possible duplicate of [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen May 14 '16 at 10:10

1 Answers1

0

Like this?

if(!text1.value.match(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(\w|\-){16}$/)

Allowing only the characters you mentioned, needs exactly 16 of them and atleast one uppercase/lowercase/number...

Personal note in case you are trying to ensure password strength

Fabian N.
  • 3,807
  • 2
  • 23
  • 46
  • no that's not right. the code i have has mandatory for numbers, uppercase and lowercase letters. in your code you can enter if you want only numbers or letters – kimfarid May 14 '16 at 11:46
  • Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as [accepted](http://i.stack.imgur.com/QpogP.png) – Fabian N. May 14 '16 at 12:13