Welcome, Guest
Username: Password: Remember me

TOPIC: Looking for simple text validation for names

Looking for simple text validation for names 3 years 11 months ago #51746

  • mapwork
  • mapwork's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
How can I limit the validate the input of a short text field for names not too rigid manner? I have seen very complex expressions in the Regular Expression Library but they seem very rigid and complex. I would like to work with something simple, but less prone to errors and easily adaptable by myself and others.


Any string that only contains letter a-z; A-Z; spaces " "; commas ","; periods "." ,"'"sign (as in: O'Higgins) and "-" (as in: Smith-Jones)should be considered as valid.

e.g. | Katharina A. Zeta-Jones | O'Higgins, Bernardo | J.F. Kennedy | Jan van Dam | jacky | should all pass.

Strings containing other characters and or numbers should be rejected.
e.g. Yours4ever | Love@firstsight | Jack & Jane | John + Emmy | would not be valid inputs.


Thanks for anyone who can give a hand
The administrator has disabled public write access.

Re:Looking for simple text validation for names 3 years 11 months ago #51748

  • mapwork
  • mapwork's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
After some googling, puzzling and trying I came up with this one.

/^[a-zA-Z'-'\.\s\-]{3,40}$/

I learned:

\. = a period
\s = a space
\- = a hyphen

I don't understand the syntax for the single quote: ' but it's in there.

{3,40} means the string must be between 3 and 40 characters long to be considered as valid.

I hope this serves other non programmers as well
The administrator has disabled public write access.

Re:Looking for simple text validation for names 3 years 11 months ago #51759

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6451
  • Thank you received: 844
  • Karma: 249
mapwork wrote:
I hope this serves other non programmers as well
Thanks to share your experience, feel free to add this possibility to Regular Expression Library in the limesurvey documentation part, it's a wiki.

:)
The administrator has disabled public write access.

Re:Looking for simple text validation for names 3 years 11 months ago #51779

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
mapwork wrote:
After some googling, puzzling and trying I came up with this one.

/^[a-zA-Z'-'\.\s\-]{3,40}$/

I learned:

\. = a period
\s = a space
\- = a hyphen
Please add this (and everything else you learned) to our manual at the regex wiki page, it will helpm other users a lot.

Thanks!

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.105 seconds
Donation Image