0

Is there a simple regex that only matches one word with no white space?

I am using parsley to validate Cognito username. Cognito allows any character for username, as long as there is no whitespace, and returns an error if you enter a whitespace that says your username must match the pattern [\p{L}\p{M}\p{S}\p{N}\p{P}]+

According to regex sandbox sites, this pattern matches any number of words separated by whitespace. To complicate matters, parsley pattern matching marks anything I type as invalid with this regex

data-parsley-pattern="[\p{L}\p{M}\p{S}\p{N}\p{P}]+"

Surely there is a simpler regex for one word with no whitespace? Preferably one that will not blow up parsley?

Arlo Guthrie
  • 1,152
  • 3
  • 12
  • 28
  • 2
    Try `^\S+$`..... – Wiktor Stribiżew Oct 10 '18 at 20:15
  • Have you tried your pattern? Because it doesn't make much sense. https://regex101.com/r/yqfq0p/1 – Olian04 Oct 10 '18 at 20:16
  • Yeah, that pattern matches anything except white space. But when you use it in a regex tester, it will match both words on either side of the white space instead of rejecting the string. Parsley doesn't seem to understand the pattern, though. Yours works like a charm, thanks! – Arlo Guthrie Oct 10 '18 at 20:23

0 Answers0