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

    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    Totally confused


    Hi all.

    I am using a jquery validator plugin.

    I am trying to make my own plugins, but all the ones on the internet seems to have charaters that are not present in the supplied validation.

    Here is what the supplied regex looks like...

    Code:
    "telephone":{
    "regex":"/^[0-9\-\(\)\ ]+$/",
    "alertText":"* Invalid phone number"},	
    "email":{
    "regex":"/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/",
    "alertText":"* Invalid email address"},	
    "date":{
    "regex":"/^[0-9]{4}\-\[0-9]{1,2}\-\[0-9]{1,2}$/",
    "alertText":"* Invalid date, must be in YYYY-MM-DD format"},
    The regex I found which I would like to use looks like this:

    Code:
    ^\d*[0-9](\.\d*[0-9])?$
    Am I seeing two kinds of regex here? I don't see ? characters in the supplied regex. And slashes look like they are used differently.

    Confused!

    Cheers,
    Doug
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    the / character is used as a boundary, to show where the regexp begins and ends. Some regexp parsers don't use them, so sometimes you see them omitted. ^ and $ designate the beginning and ending of a string, respectively. So where you see /^something$/ it can be considered the same as ^something$ for example purposes.

    As for the rest of your post...what do you mean? You posted 3 regular expressions inside a javascript array, then posted a fourth and said something about question marks. Question marks are special characters in regular expressions, if you would like to include one in a pattern it must be escaped, like this: \?

    Other than that, you'll have to be more specific.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    interesting...


    ahh I see.

    Sorry about my wording, let me explain a bit further with some coherence!

    I am trying to pass particular regexp through this javascript parser. But I can't other regexp ones I find to work from regexlib dot com.

    I tried adding those boundary charaters but it still doesn't work. So I can't figure out where I am going wrong! I thought that perhaps is the regex is going through a parser, I need to do more then add boundaries. As in maybe some characters need to be replaced or added within the regex code so it doesn't get screwed up in the parser.

    I am new to regex. You mentioned regexp. Are they different things?

    Thanks for your help and patience!

    Cheers,
    Doug
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Some people include the P, some don't. Larry Wall (the inventor of Perl, and arguably the inventor of modern regular expressions) calls the "reg[Ee]xp?"

    What are you trying to do with that regular expression you posted? It looks like you're just trying to validate decimal numbers with at least one digit before the decimal place. If that's the case, you really just want:
    Code:
    /^\d+(\.\d+)?$/
    To add it to your script you'd do:
    Code:
    "telephone":{
    "regex":"/^[0-9\-\(\)\ ]+$/",
    "alertText":"* Invalid phone number"},	
    "email":{
    "regex":"/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/",
    "alertText":"* Invalid email address"},	
    "date":{
    "regex":"/^[0-9]{4}\-\[0-9]{1,2}\-\[0-9]{1,2}$/",
    "alertText":"* Invalid date, must be in YYYY-MM-DD format"},
    "someNumberType":{
    "regex":"/^\d+(\.\d+)?$/",
    "alertText":"* Invalid number type.  There must be a leading digit before the decimal, and digits after the decimal if one is included."},
    I don't know how your validation thing works, but wherever you check for "telephone" you can change it to "someNumberType" to get the new regexp and the new error message.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    Thanks


    Thanks for that. I will give it a go!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    6
    Rep Power
    0

    ... hmm didn't work... but


    HMM well it didn't work. I thought it would because it looked to short and simple. My attention now turns to the rules for accepting regex because I now know that the problem probably isn't the regex.

    Here is a function tied in with the functions. Maybe I can change something in here to make the rules more acceptable?
    Code:
    var loadValidation = function(caller) {VALIDATIONS TO BE EXECUTED
    
    rulesParsing = $(caller).attr('class');
    rulesRegExp = /\[(.*)\]/;
    getRules = rulesRegExp.exec(rulesParsing);
    str = getRules[1]
    pattern = /\W+/;
    result= str.split(pattern);	
    		
    var validateCalll = validateCall(caller,result)
    return validateCalll
    };
    Does anything in there ring any bells? ITs almost as if it only accepts the most primitive regex's. From looking at the supplied regex validations, they don't employ that many expressions as compared to make examples I have seen.

    And ideas?

    Cheers,
    Doug

IMN logo majestic logo threadwatch logo seochat tools logo