Check out the LimeSurvey source code on GitHub!

Looking for simple text validation for names

More
6 years 2 months ago #51746 by mapwork
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

Please Log in to join the conversation.

More
6 years 2 months ago #51748 by mapwork
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

Please Log in to join the conversation.

More
6 years 2 months ago #51759 by DenisChenu
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.

:)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
6 years 2 months ago #51779 by Mazi
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)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form