Regex for alpha,hyphen,space,min,max

Last post 07-10-2009 1:51 PM by gchoi363. 4 replies.

Sort Posts:

  • Regex for alpha,hyphen,space,min,max

    07-08-2009, 7:32 PM
    • Member
      point Member
    • gchoi363
    • Member since 07-08-2009, 7:29 PM
    • Posts 4

    Hey

    Im doing javascript and I have so far:

    var matchCase = /^[a-zA-Z -]+$/;

    which checks for alphabet lower and upper case, a space and hyphen. I was wondering if there's a way for me to also set the maximum and minimum length of the match case.

    I tried adding {min,max} after the bracket but that didn't work out (min and max being some kind of integer, not the variable or string)

    Thanks.

  • Re: Regex for alpha,hyphen,space,min,max

    07-08-2009, 9:00 PM
    Answer
    • All-Star
      90,773 point All-Star
    • SGWellens
    • Member since 01-02-2007, 4:27 PM
    • Twin Cities, MN
    • Posts 7,411
    • Moderator
      TrustedFriends-MVPs

     

    Ultrapico This site has a great free tool for building Regular Expressions (Expresso).
    Steve Wellens

    My blog
  • Re: Regex for alpha,hyphen,space,min,max

    07-09-2009, 12:55 PM
    • Member
      point Member
    • gchoi363
    • Member since 07-08-2009, 7:29 PM
    • Posts 4

    Hey

    Thanks for the reply. I actually tried searching for a software that helps me to do regex but most either I had to pay for or didn't simply work and you've just found the one that I needed :]

    Well after playing around with it for a while, I've come across this: /^[A-Za-z -]{1,}$/

    So I guess it's that "+" sign that didn't let me do {min,max}. Thanks again for the reply!

    Also, do you know any website that is good at debugging a code for silly mistakes like missing { or just simple spelling error? I've been using the firefox's error console but that doesn't seem to catch it.

  • Re: Regex for alpha,hyphen,space,min,max

    07-10-2009, 1:51 PM
    • Member
      point Member
    • gchoi363
    • Member since 07-08-2009, 7:29 PM
    • Posts 4

    Sorry, it somehow ended up being a double post. Please refer to the comment below this, thanks

  • Re: Regex for alpha,hyphen,space,min,max

    07-10-2009, 1:51 PM
    • Member
      point Member
    • gchoi363
    • Member since 07-08-2009, 7:29 PM
    • Posts 4

    Hey, I was wondering, after few more regex coding, I came across trying to allow few of the special characters

    I wanted to know if there's a possible way to allow both of the square brackets.

    The problem is that whenever I put it, it's rather ending the exception list since all my allows keys are within the bracket

    So for example, I have [a-zA-Z] then I want square bracket, so I tried [][a-zA-Z] but that didn't work out. Is there some kind of special key character I need to be able to match it?

    Thanks

Page 1 of 1 (5 items)