US Canada Zip code regular expression for validation

US Canada Zip code regular expression for validation for use at cForms II plugin for word press

Regex US or Canada zip code validation test
  1. (required)
 

cforms contact form by delicious:days

(^\d{5}(-\d{4})?$) US
| or
((^[ABCEGHJKLMNPRSTVXY]{1}[0-9]{1}[A-Z]{1}\s[0-9]{1}[A-Z]{1}[0-9]{1}$)|(^[ABCEGHJKLMNPRSTVXY]{1}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{1}[0-9]{1}$)) Canadian

Regular expression for validation of Canada zip code

Regular expression for validation of Canada zip code

Test the regular expression for validation of Canada zip code at work at the below form.  Upon submission you should get a validation passed or failed message based on validity of zip code entered.  The regular expression considers both scenarios, a space exists between zip codes parts or omission of the space between zip code parts.

Canada zip code validation test
  1. (required)
  2. Captcha
 

cforms contact form by delicious:days

Regular Expression:

(^[ABCEGHJKLMNPRSTVXY]{1}[0-9]{1}[A-Z]{1}\s[0-9]{1}[A-Z]{1}[0-9]{1}$)|(^[ABCEGHJKLMNPRSTVXY]{1}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{1}[0-9]{1}$)

Explanation on how the regular expression is formed.:

( Group start
^ Start
[ABCEGHJKLMNPRSTVXY]{1} First a character in upper case matching the list
[0-9]{1} Next a digit
[A-Z]{1} Next  any one character in upper case
\s Next a space
[0-9]{1} Next a digit
[A-Z]{1} Next any one character in upper case
[0-9]{1} Next a digit
) Group end
| or
( Group Start
^[ABCEGHJKLMNPRSTVXY]{1}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{1}[0-9]{1}$ Same as above except no space between the two zip parts.
) Group end

Variations in forming regular expressions for validating Canadian zip code:

\d{1} [0-9]{1}
* The (*) star can be used to construct the first part zip to be with or without a space at end.

Instead of [0-9], the code can be shortened buy using \d to represent all digits.  The Regular expression stated above duplicate the code, one with a space and other without a space.  The * command can be used to repeat the search.

Usage of regular expression to validate Canadian Zip code at CFORMS II:

regular expression canada zip code cform II

regular expression canada zip code

 

At cforms add a single line form field. Enter the regular expression codes at the field validation section for validating the data enter by the user matches with the Canadian Zip code format.

Cheers!

Regex First and Last Name validation on cforms

First and Last Name Validation test
  1. (required)
 

cforms contact form by delicious:days

^[A-Za-z]*\s{1}[A-Za-z]*$

^ Start
[A-Za-z] Next charcter lower or upper case
* More than one character allowed
\s{1} One space
[A-Za-z] Next character lower or upper case
* More than one character allowed
$ End

Variations:

^[A-Z]{1}[a-z]*\s[A-Z]{1}[a-z]*$

The first character of first name is of upper case and the a space and first letter of last name is of upper case.

cform:

Regex_FirstName_LastName_validation

Cheers!

 

 

Cforms ii plugin – Forms data not saving to database

The setting for tracking forms submissions for cforms plugins is straight forward, however when tracking does not work on the word press hosted at windows azure cloud as this site is.

After a  long search landed up with a suggestion to  check the php logs, and the next project was to locate the php logs.  If fact it was simple,  yes you are correct, there is another yet another plugin – Life is so easy with word press, isn’t it…

Installed the Error Log Monitor plugin, once activated the plugin added a widget to dash board listing the recent error.

Voila!

WordPress database error Data too long for column ‘ip’ at row 1 for query

INSERT INTO wp_cformssubmissions
(form_id,
email,
ip,
sub_date)
VALUES      (,
’email@email.com’,
‘xxx.xxx.xxx.xxx:65015’,
‘2013-06-15 20:21:31’)

Solution:

Increase the field size for the IP address field or modify the code to update only the IP address.  I am comfortable in getting the field expanded!

Cheers!