CMS Made Simple Forums

Validation in CGBetterForms
Page 1 of 1

Author:  rooon [ Mon Apr 15, 2019 4:56 pm ]
Post subject:  Validation in CGBetterForms

Hi all,

In CGBetterForms I want to use validation rules of type
"Match field values against a regular expression"
but somehow my regex are not working.

<input type="text" name="email">

For example: a@b.c has to result in not valid, and is valid.
I tried this regex:

<textarea name="message">

For example: www. in the message should return not valid.
Edit /^(?:(?!http:|https:|ftp:|www|\/\/|\\\\|\.htm|\.php).)+$/gi

How to create the 2 regex strings for these fields?
And what is the proper way to insert a regex in CGBetterForms?

Thanx in advance.


Author:  rooon [ Tue Apr 16, 2019 10:19 am ]
Post subject:  Re: Validation in CGBetterForms

I think it is working with this regex on the input (email)
<input type="text" name="email">


This regex for the textarea (message field) will result in a validation error if there is an url in the textarea and/or the amount of characters is less then 5.
<textarea name="message">


Author:  MantaPro [ Wed Apr 17, 2019 8:44 pm ]
Post subject:  Re: Validation in CGBetterForms

You asked about how to use a regex with CGBetterForms

From the CGBetterForms/Validation tab select the "Validate via Smarty Template" then enter your smarty regex; only output an error message if it fails validation.

Here's an example I used for email validation (on a form that previously suffered a lot of spam; hence the obfuscated field names)
{* Email -  valid format *}
{if !preg_match('/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $fld0130)}
   Invalid fld0130, please correct
(my form template uses a smarty array to translate the unfriendly field references to human readable labels

I find this website really useful for regex

good luck

Author:  rooon [ Sun Apr 21, 2019 1:31 pm ]
Post subject:  [SOLVED] Validation in CGBetterForms

MantaPro, thanx for your reply.
At the end it works well with these "Match field values against a regular expression" validation rules:
<input type="text"> (email from South/West Europe)
match pattern /^([a-z0-9_\+\-\.]{1,40})@([a-z0-9\-\.]{2,40})\.(biz|com|edu|eu|info|int|net|org|be|de|fr|ie|it|lu|nl|at|pt|es|uk|ch)$/i

<input type="text"> (min. 2 characters without leading/trailing spaces)

<textarea> (url not allowed)

<select> (empty value or '-' not allowed)

I'll keep your template idea in mind for other forms.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group