• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Validation in CGBetterForms
PostPosted: Mon Apr 15, 2019 4:56 pm 
Offline
Forum Members
Forum Members

Joined: Mon Dec 05, 2011 4:40 pm
Posts: 73
Location: Voorburg, Nederland
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.

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

For example: a@b.c has to result in not valid, and a@bb.nl is valid.
I tried this regex:
/^([a-z0-9_\+\-\.]{1,40})@([a-z0-9\-\.]{2,40})\.(nl|com|org|info|eu)$/gi

Code:
<textarea name="message">

For example: www. in the message should return not valid.
/(http:|https:|ftp:|www|\/\/|\\\\|\.htm|\.php)+/gi
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.

Ronald


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Validation in CGBetterForms
PostPosted: Tue Apr 16, 2019 10:19 am 
Offline
Forum Members
Forum Members

Joined: Mon Dec 05, 2011 4:40 pm
Posts: 73
Location: Voorburg, Nederland
I think it is working with this regex on the input (email)
Code:
<input type="text" name="email">

/^([a-z0-9_\+\-\.]{1,40})@([a-z0-9\-\.]{2,40})\.(nl|com|org|info|eu)$/i


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.
Code:
<textarea name="message">

/^((?!https?:|ftp:|www|\.php|\.html?|[\/\\]{2}).){5,}$/i


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Validation in CGBetterForms
PostPosted: Wed Apr 17, 2019 8:44 pm 
Offline
Forum Members
Forum Members

Joined: Sun Feb 03, 2008 8:14 pm
Posts: 76
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)
Code:
{* 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
{/if}
(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 https://regex101.com/

good luck


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: [SOLVED] Validation in CGBetterForms
PostPosted: Sun Apr 21, 2019 1:31 pm 
Offline
Forum Members
Forum Members

Joined: Mon Dec 05, 2011 4:40 pm
Posts: 73
Location: Voorburg, Nederland
MantaPro, thanx for your reply.
At the end it works well with these "Match field values against a regular expression" validation rules:
Code:
<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)
/^(?=\S+).{2,}\S+$/i

<textarea> (url not allowed)
/^((?!https?:|ftp:|www|\.php|\.htm|\\\\|\/\/).)*$/i

<select> (empty value or '-' not allowed)
/^(?![\s-]*$).+/

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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Hosting Nation - Managed CMSMS Hosting