Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

not allowing double space

Last post 04-05-2008, 5:24 PM by ddrudik. 3 replies.
Sort Posts: Previous Next
  •  04-04-2008, 5:57 PM 41101

    not allowing double space

    I need a regex for checking if a Xbox Live Gamertag is valid:

    Aa-Zz, 0-9, single spaces, can't start with a number (min 1, max 15)

    I can't get it to not allow double spaces..

    Any idea?

     

  •  04-04-2008, 6:50 PM 41104 in reply to 41101

    Re: not allowing double space

    can a single space be a valid input? From your rules, as they are stated, it can.

    if yes, then try this. Your regex engine must support look-arounds:

    ^(?!.*\x20{2})[A-Za-z\x20][A-Za-z\d\x20]{0,14}$

  •  04-05-2008, 9:05 AM 41109 in reply to 41104

    Re: not allowing double space

    Thanks!

     It's for PHP. I don't know if it supports it, but I'll try it.

  •  04-05-2008, 5:24 PM 41118 in reply to 41109

    Re: not allowing double space

    It does support it:

    if (preg_match('/^(?!.* {2}|^\d)[A-Z\d ]{1,15}$/i',$sourcestring)) {

     // do something

    } else {

     // do something else

    }


View as RSS news feed in XML