Help with some Regex

Discussion in 'JavaScript' started by getwiththeprogram, Apr 9, 2007.

  1. #1
    Hi,

    I am looking at updating a site for someone and they have asked for some tweaks which are new to me, from having a look online it seems I need or its best to use serveral regex's to check prior to a form submission but I cant find a easy to follow tutorial which I could adapt.

    Any help or links to guides to follow please :confused:

    1) first letter of a field must be a letter anything after is allowed
    2) zip code in format of AB12 AB13 or AB1 AB1 must be uppercase
    3) phone number in 12345 111111 or 1234 1234
    4) email address (lowercase and check for @)
    5) credit card to be 1234 1234 1234 1234

    Thanks to anyone for taking the time to read my post.
     
    getwiththeprogram, Apr 9, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Validating the input on the client's side seems rather pointless to me, because the user can just disable JavaScript and submit the form like he wants to. The input should always be validated on the server-side.

    If you want to do an additional pre-check, that's fine. But a waste of time, if you ask me.
     
    nico_swd, Apr 9, 2007 IP
  3. getwiththeprogram

    getwiththeprogram Peon

    Messages:
    120
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes I agree, and I will again make a point to him of saying they should move to a server side validation, but client side pre checks are ok as well.
    Bit out of my depth I have done simplish javascript before to check if form fields are blank but this uppercase and formatting stuff seems to be quite intense.
     
    getwiththeprogram, Apr 9, 2007 IP
  4. getwiththeprogram

    getwiththeprogram Peon

    Messages:
    120
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Any pointers? The guides I have seem to just confuse me further, and I cant seem to find anything to help me test/try out variations.
     
    getwiththeprogram, Apr 12, 2007 IP