0

I'm using input pattern attribute to valiate a form. I have some text fields that allow aplphanumeric digits, some selected characters (',-, accented chars, spaces) and at least one alphabetic character, with a min. length of 3.

my current regex is:

[0-9a-zA-Z-'áéíóúÁÉÍÓÚàèìòù ]{3,100}

and I can't really grasp the concept of how to require at least one character; I know I should use +, but the rest of the regexp fails.

Andrew P.
  • 160
  • 1
  • 8
  • 1
    The `{3,100}` is currently repeating the previous token (the character set) 3 to 100 times, do you want to change that to `+`? What do you mean, `rest of the regexp fails`? – CertainPerformance Nov 23 '18 at 09:04
  • 1
    Side note: Instead of `{3,100}`, you could use `{3,}`, it won't matter though. – Micha Wiedenmann Nov 23 '18 at 09:06
  • 1
    See [this answer](https://stackoverflow.com/a/3850256/3832970). You are probably mixing quantifiers. – Wiktor Stribiżew Nov 23 '18 at 09:07
  • 1
    It seems to me that you are confused about the `+`. `+` is the same as `{1,}`. In simple cases you get away with `*` and `+` but in more complex cases you need `{n,m}` or a variation thereof. – Micha Wiedenmann Nov 23 '18 at 09:07
  • 1
    https://regex101.com/ is a great resource for tinkering with regular expressions. – Micha Wiedenmann Nov 23 '18 at 09:08
  • I solved this by adding a positive lookahead to make sure there was at least one alphanumeric character, then by checking other special characters I needed in the following square brackets. full regexp is (?=.*[a-zA-Z])[a-zA-Z0-9'-áéíóúÁÉÍÓÚàèìòù ]{3,100} – Andrew P. Nov 26 '18 at 17:30

0 Answers0