0

I'm trying to make a Regex for password strength. My aim is to have password with both letter and non letter characters. But I was unable to have the "non-letter" characters. I have this

<input minlength="6" type="password" required pattern="[(\p{L}]*" name="password">

but it checks only for alphabetic characters.

How can I make it so that it checks for string that contains at least one alphabetic and one non-alphabetic character.

ilhan
  • 8,700
  • 35
  • 117
  • 201
  • 2
    JS regex engine does not support Unicode category (property) classes. If you use ASCII only aware regex, you can use `"(?=[a-zA-Z]*[^a-zA-Z])(?=[^a-zA-Z]*[a-zA-Z]).*"` – Wiktor Stribiżew Oct 17 '16 at 08:45
  • So, the question is: do you need to support all Unicode letters? – Wiktor Stribiżew Oct 17 '16 at 12:08
  • @WiktorStribiżew, Yes, I need to support all Unicode letters. Like the letters ÖöÇ窺ĞğÜüİıûîæßμиж and like non-letters . The problem with a-z is that when user puts ü it is not recognized as a "letter". – ilhan Oct 17 '16 at 13:11
  • Then do not rely on `pattern` attribute, just have a look at [`XRegExp`](http://xregexp.com/). – Wiktor Stribiżew Oct 17 '16 at 13:39
  • As for diacritics, or emojis, you could use the Unicode regex (currently, Chrome and FF use this type of ES6 regex in HTML5 pattern attribute), but still, there is no support for Unicode category classes in JS ES6. – Wiktor Stribiżew Oct 18 '16 at 12:50

1 Answers1

1

This should do it:

[^\x00-\x7F]+

It matches any character which is not contained in the ASCII character set (0-127, i.e. 0x0 to 0x7F). You can do the same thing with Unicode:

[^\u0000-\u007F]+

@Jeremy Ruten's answer in this question

Community
  • 1
  • 1
Royts
  • 501
  • 6
  • 14
  • I doubt [`¤§‘’“`](https://regex101.com/r/HTa4mJ/2) are Unicode letters. Besides, you cannot match chars outside of BMP plane with a negated character class in JS ES5 regex. – Wiktor Stribiżew Oct 18 '16 at 12:47