Search

I am struggling to figure out how to construct a field validation to limit the value input to one word.

This should be simple except that I haven’t been able figure out away to parse out the spaces or punctuation.

[A-Za-z]+ will work for vanilla English but leaves out a range of characters that make up word in the broader sense such as é, Ø, Ì, æ, û, ý, Ç — etc. It seems that I need to use a positive regex (this is what I want, not this is what I don’t want)

Any wisdom? If I have to I’ll settle for just ensuring spaces are caught, but I can’t even do that :-(

Does the following work?

^\w+$

@designermonkey Nope, it appears to be, functionally, the same as [A-Za-z]. It can cope with cafe not café. Or Çelik.

Ok. If you want to match words, whatever character, and only one word then try the following...

^\S+$

This matches beginning and end of string, with one or more character that isn't a space, so one single string.

Hope it helps.

PS, intrigued that the first didn't match. Back to the reading books for me on unicode then ;o)

@designermonkey Thanks! That did the business. I need re-read “Mastering Regular Expressions.”

I actually hate this one, but this is quite good at testing regular (perl) expressions and it's free, There's also a desktop (air) application.

Useful resource there Thomas, thanks.

I use Patterns on the Mac.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details