1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What Does This Say?

Discussion in 'jQuery' started by offthedome, Feb 1, 2013.

  1. #1
    So I know what it does, because I found it online. It's a phone number validator. But that seemingly long list of seemingly random symbols in the first line of the function, I don't know where to look to write javascript in such shorthand.

    [javascript]
    function ValidatePhone() {
    var phoneRegExp = /^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/;
    var phoneVal = $("#txtPhone").val();
    var numbers = phoneVal.split("").length;
    if (10 <= numbers && numbers <= 20 && phoneRegExp.test(phoneVal)) {
    alert("SUCCESS");
    }
    }

    [/javascript]
     
    offthedome, Feb 1, 2013 IP
  2. Dangy

    Dangy Well-Known Member

    Messages:
    841
    Likes Received:
    25
    Best Answers:
    2
    Trophy Points:
    155
    #2
    That's about as short hand as it gets right there.. But that is a RegExpression that long list of code so continue your search there if you think you can do it differently.
    It makes sure the format is "XXX-XXX-XXXX"
     
    Dangy, Feb 7, 2013 IP
  3. madskillsmonk

    madskillsmonk Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #3
    It's simply a function that uses a regular expression to make the that the phone number is valid (or at least follows the correct amount of numbers as it should). Regular expressions (or regexs for short) are used very often in things like this or making sure emails are valid, etc. Some people come up with regex's themselves, but most people just google "phone number regex" and find what they are looking for as they are not easy to remember/create.
     
    madskillsmonk, Feb 8, 2013 IP
  4. brandon813

    brandon813 Member

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #4
    Regular expressions are extremely tedious to write. If you want some good education information AND some free expressions, go to RegExpLib.com

    You could create several validators just like the one you have and only need to update the expression part and function name.

    As to what that expression is actually doing, it's forcing the string to adhere to the rules within it. This site has great information on what each part of the regular expression string should do;

    http://www.regular-expressions.info/reference.html
     
    brandon813, Feb 12, 2013 IP