Page 1 of 1

Formbuilder validate a textfield

Posted: Wed Jan 12, 2022 11:06 pm
by janvl
Hi,

i have managed to use a validation with a number through the regex like /^(27)/ for number 27.

Now i am looking to find how i validate a text-input with a word, i tried /^(dog)/ for the word dog but that does not work.

I can find lots of regex-tests but does not seem to fit my wish, do i need javascript here?
and when how do i enter that in CMSMS? Does anyone have an example please?

Kind regards,
Jan

Re: Formbuilder validate a textfield

Posted: Thu Jan 13, 2022 12:44 am
by DIGI3
It's a perl style regex according to the docs, so for dog (case insensitive) you'd just do:

Code: Select all

/dog/i
See https://perldoc.perl.org/perlre

Re: Formbuilder validate a textfield

Posted: Thu Jan 13, 2022 7:57 am
by velden
Additionally I think you need to add a ^ and $ to check for the whole string, not a substring. E.g. dog vs dogma vs bulldog

Code: Select all

/^dog$/i

Re: Formbuilder validate a textfield [SOLVED]

Posted: Thu Jan 13, 2022 11:37 am
by janvl
Thanks a lot!

i have build this into the form and it works.

Do not laugh, i forgot to mark that the regex must be used . .

Since there is a real explosion of spamming through contact-forms i need to build validation in those forms.

Regards,
Jan