dtb
2009-09-21 21:54:55
i need it to detect spaces though
David
2009-09-21 21:56:13
Your current regex says: "I match if the string is made of these characters and 3 to 16 characters in length OR if it contains a space"
dtb
2009-09-21 21:57:14
Ok i'm a novice sorry. any advice on how to modify it so it matches the characters and is 3-16 in length and contains no spaces?
David
2009-09-21 22:02:36
Just remove `|\s` from the end of the regex.
dtb
2009-09-21 22:04:41
ok. here so we have^([a-zA-Z0-9!@#$%^:'"|~`?/{}]{3,16})$That matches anything that is NOT a string of ASCII between 3-16 in length. So now I want it to stop when it detects a space. what shall i add?
David
2009-09-21 22:17:35
@David: No, that matches anything that **is** such a string - the leading `^` means "the start of the string", not **NOT**.
RichieHindle
2009-09-21 22:25:41
If I understand correctly what you're trying to do, replace the `$` at the end with `($|\s)` But to be sure you should add some examples of valid and invalid input to your question. Note the parentheses around `($|\s)`
dtb
2009-09-21 22:25:46
A:
A simpler answer would be:
^([^\s]{3,16})$
which means "the whole string must consist of three to sixteen repeats of anything other than whitespace."
That will allow accented characters as well, but that's probably something you'll need to accept anyway.
RichieHindle
2009-09-21 22:28:24
A:
csharptest.net
2009-09-22 03:17:47
Thanks for the explanation. I wasn't going mad, it appears there is some problem with the way the expression is used. My page still allows me to enter spaces undetected. the string is fine though. I've picked the spaces out with an if statement now to save time. Thanks though!
David
2009-09-22 10:45:24