Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Edge 22 posts 56 karma points
    Apr 03, 2017 @ 03:14
    Anthony Edge
    0

    A few handy validation Regular Expressions

    I've jumped into RegEx without much experience and thought adding a starter set of validations might help others get some basic functionality into their forms more quickly (and save the time I spent Googling and trial and error).

    Mandatory Valid Email

    By design this rule ensures domain formatting has no spaces, commas, double full stops or end with a full stop.

    Email is a tricky one to validate because almost almost anything before the "@" can be valid if it's within quotes. For that reason, this simple rule states:

    1. There must be something before the @
    2. There must be an @
    3. After the @ must follow characters that do not include a comma, full stop or a space
    4. Next must follow at least one group that starts with a full stop before a string of characters excluding a comma, full stop or a space

    RegEx = ^.+@([^,\.\ ])+(\.([^,\.\ ])+)+$

    --

    Phone number - Min 10 digits (not mandatory)

    Domestic phone numbers in Australia (standard landline or mobile) which inlclude an area code, are a minimum of 10 digits. So making sure a phone number has a minimum of 10 is a sufficient test. Even if users add brackets, spaces, + or dashes it will pass. So people adding international codes or extension numbers won't be penalised. Of course, promotional business numbers may get blocked, such as 130 000, or 911.

    RegEx = ^(\D*(?:\d\D*){10,})?$

    --

    Valid Australian Landline or Mobile Phone Number

    If you want to get very strict in Australia, you can mandate a strict landline or mobile number format. I doubt it's required though, unless you're sure your audience is domestic only, in which case it might slow down a few spam bots.

    RegEx = ^(\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3})?$

  • Nicholas Westby 2005 posts 6843 karma points c-trib
    Apr 03, 2017 @ 04:13
    Nicholas Westby
    0

    Hi Anthony,

    Thanks for this!

    I actually hope to include a few sample validations with Formulate at some point: https://github.com/rhythmagency/formulate/issues/24

    Until then, it would make a lot of sense to include your samples as documentation to supplement the existing documentation on validations: http://www.formulate.rocks/validations

    If you want to submit a pull request to get this documentation included in the main documentation site, you can do so here (the "gh-pages" branch of the main repository): https://github.com/rhythmagency/formulate/tree/gh-pages

    It's written in markdown. For reference, here's the markdown for the validations documentation I linked to above: https://raw.githubusercontent.com/rhythmagency/formulate/gh-pages/validations.md

    Let me know if you have any questions regarding submitting pull requests.

  • Anthony Edge 22 posts 56 karma points
    Apr 03, 2017 @ 06:25
    Anthony Edge
    0

    They might prove helpful to folks like me. I'm unlikely to have a chance to incorporate them anytime soon. AE

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies