-2

I want 6 regular expressions in jquery for these following conditions.

  1. Limit of the letters = 200 (max 431)
  2. The maximum allowed same consecutive letters=5
  3. If "space" is pressed,no more symbols to be accepted
  4. The sign "-" is accepted,but only twice
  5. The sign "." is accepted,but only twice
  6. The sign "_" is accepted,but only twice

I need 6 separate regular expressions for these conditions.

Can you help me in developing these regular expressions.

Thank you in advance.

Haider
  • 19
  • 7
  • please share your efforts ! – Gilles Gouaillardet Aug 28 '17 at 01:23
  • `If "space" is pressed` would not be a PHP process. `I want 6 regular expressions` is not how SO works. Show us the code you are using and what your issues are and we'll help... or ask about some specific coding aspect and we can help with that. This is too broad as is. – chris85 Aug 28 '17 at 01:27
  • ^(?:(\w)(?!\1\1\1\1))+$ i have used this but this is not allowing me to enter any special character like "-","_". – Haider Aug 28 '17 at 01:29
  • yes i know but I am confused whatever i am using is not working – Haider Aug 28 '17 at 01:32
  • Did you look at what `\w` is? http://www.regular-expressions.info/shorthand.html `\w stands for "word character". It always matches the ASCII characters [A-Za-z0-9_].` The underscore is allowed, you'd need to provide an example of how that is failing you. – chris85 Aug 28 '17 at 01:33
  • Now i have these two regex 1) ^(?!.*[._]{2})[a-zA-Z0-9_.]+$ 2) ^(?:(\w)(?!\1\1\1\1))+$ first one is not allowing me to add any 2 "-","_","." second one not allow more than 5 consecutive characters but it also not allow to add any special character – Haider Aug 28 '17 at 01:41
  • Why 6? What is the sample string you are running against? – chris85 Aug 28 '17 at 01:42
  • I have a textbox and i need if user type consecutive 5 letters then message should be shown to him like "abvvvvvv" or if he types "ab.c.." or "a_b__" or "a-bc--" – Haider Aug 28 '17 at 01:51

1 Answers1

0

Limit of the letters = 200 (max 431)

/(\w.*){201}/

The maximum allowed same consecutive letters=5

/(\w)(\1){4}/

If "space" is pressed,no more symbols to be accepted

/ ./

The sign "-" is accepted,but only twice

/(-.*){3}/

The sign "." is accepted,but only twice

/(\..*){3}/

The sign "_" is accepted,but only twice

/(_.*){3}/
pguardiario
  • 53,827
  • 19
  • 119
  • 159