#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0

    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.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    You need regular expressions to validate those?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0
    Well all I know is that it says Validation regex, where I place the regex.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    What are the exact rules you want to include in the regexes? Be as specific as possible with what you want.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    9
    Rep 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.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    That's great and all, but
    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.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    9
    Rep 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.
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    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.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    9
    Rep 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?
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0
    Sorry I have just noticed that the phone number does include mobile numbers as well.

IMN logo majestic logo threadwatch logo seochat tools logo