Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Form Validation

  • 10-03-2008 12:20PM
    #1
    Registered Users, Registered Users 2 Posts: 224 ✭✭


    Hi,

    I have a form validation and need to change it. Basically the validation checks a code entered by the user. There are 3 parts to the code, first part 3 alphanumerics, 2 part a year e.g. 2008, 3 part 3 numbers.

    aaa/YYYY/nnn
    e.g. ab1/2008/123

    function validateItemID(input){
    var validformat=/^[a-zA-Z0-9]{3}\/[0-9]{4}\/[0-9]*$/
    if (!validformat.test(input.value)){
    alert("Invalid Item ID format. Must be formatted \"aaa/YYYY/nnn\"")
    return false }
    else {
    return true
    }
    }
    I need to change the code so it will allow any amount of alphanumerics in the first part of the entered code.
    Any help would be appreciated


Comments

  • Closed Accounts Posts: 7,144 ✭✭✭DonkeyStyle \o/


    My regex isn't great, but I think this'd work...
    var validformat=/^[a-zA-Z0-9]{3}\/[0-9]{4}\/[0-9]*$/
    Change that 3 to 0,15 ... which I think should allow anywhere between 0 and 15 alphanums for the first part... but make sure to test it out fully.

    I've got this page bookmarked for when I have to deal with regular expressions.


  • Registered Users, Registered Users 2 Posts: 224 ✭✭The Mighty Dubs


    savage stuff. that did the trick. Many thanks


Advertisement