The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Other - Please help me with the following regex for a WordPress plugin form
Discuss Please help me with the following regex for a WordPress plugin form in the Regex Programming forum on Dev Shed. Please help me with the following regex for a WordPress plugin form Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 8th, 2011, 03:18 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Time spent in forums: 1 h 52 m 3 sec
Reputation Power: 0
|
|
|
Other - Please help me with the following regex for a WordPress plugin form
I am new to regex, am needing someone to show me how to do the following for a WordPress plugin form: - Phone Number - the user should be able to enter either an Australian phone or mobile number
- Arrival Date and Time - something like this: 12/12/2012 4.30pm
- Departure Date - something like this: 14/12/2012
So could someone please help me with this? Thanks in advance.
|

December 8th, 2011, 03:36 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
You need regular expressions to validate those?
|

December 8th, 2011, 04:19 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Time spent in forums: 1 h 52 m 3 sec
Reputation Power: 0
|
|
|
Well all I know is that it says Validation regex, where I place the regex.
|

December 8th, 2011, 04:25 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
What are the exact rules you want to include in the regexes? Be as specific as possible with what you want.
|

December 8th, 2011, 04:51 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Time spent in forums: 1 h 52 m 3 sec
Reputation Power: 0
|
|
|
This what is displayed in the WordPress contact form plugin:
Validation regex:
Use to validate if form input is in a specific format. Example: If you want numbers in a text field type but do not allow text, use this regex: /^\d+$/ Can be used for text, textarea, date and password field types.
Regex fail message:
Use to customize a message to alert the user when the form fails to validate a regex after post. Example: Please only enter numbers. For use with validation regex only.
WordPress is a PHP content management system. Sorry that I can't say anything further, I just don't know anything else.
|

December 8th, 2011, 05:13 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
That's great and all, but
Quote: | Originally Posted by requinix What are the exact rules you want to include in the regexes? Be as specific as possible with what you want. |
|

December 8th, 2011, 05:27 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Time spent in forums: 1 h 52 m 3 sec
Reputation Power: 0
|
|
|
I think this what you are after, the Australian phone number is something like this: 0299999999 (without spaces, 02 is the area code, the other area codes are 07, 03 and 08) and the Australian mobile number is something like this: 0423123123 (without spaces), so with the phone numbers the user should be able to enter either a mobile or a phone number. The arrival date and time should be something like this: 12/12/2012 4.30pm. The departure date should be something like this: 14/12/2012.
|

December 8th, 2011, 07:53 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
That's exactly it.
Complicated, so I'll just give it to you.
Code:
Phone number: /^(02|03|04|07|08)\d{8}$/
Arrival D/T: #^([012]?\d|3[01])/(0?\d|1[012])/2\d\d\d\s+(0?\d|1[012])\.[0-5]\d[ap]m$#i
Departure D/T: #^([012]?\d|3[01])/(0?\d|1[012])/2\d\d\d$#
Basic date checking but isn't perfect.
|

December 8th, 2011, 09:17 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Time spent in forums: 1 h 52 m 3 sec
Reputation Power: 0
|
|
|
Thanks I will try those. Does the phone number work if a mobile number is entered instead, the user needs to have two choses with what they wish to enter, the first is the phone number and the second is the mobile number?
|

December 8th, 2011, 09:52 PM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 9
Time spent in forums: 1 h 52 m 3 sec
Reputation Power: 0
|
|
|
Sorry I have just noticed that the phone number does include mobile numbers as well.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|