Page 1 of 1

Validate a string with regex

Posted: Mon Nov 29, 2004 8:22 pm
by John Cartwright

Code: Select all

^ї_a-zA-Z0-9-]+$
I know I'm stupid. I know I hate regex. How do you make it so the string can have whitespaces?

Posted: Mon Nov 29, 2004 8:28 pm
by kettle_drum
Pretty sure its:

Code: Select all

її:space:]]

Posted: Mon Nov 29, 2004 8:29 pm
by John Cartwright
I'm sorry, I didn't clarify the question.

How can I validate a string that is letters and numbers only, but will allow whitespaces.

Posted: Mon Nov 29, 2004 8:37 pm
by kettle_drum
Oh, you can use a ^ inside [] to not match a character, i,e, you can do:

Code: Select all

"tї^aeiou]+.*s"
Which matches "thanks", "this", "trappings", etc. So you can extend this principle to check to make sure that the characters that you dont want to be in a string arnt.

Hope that made sense...its late.

Posted: Mon Nov 29, 2004 8:39 pm
by rehfeld

Code: Select all

^ї_a-zA-Z0-9ї:space:]-]+$
it matches any whitespace, not just a literal space

Posted: Mon Nov 29, 2004 8:41 pm
by John Cartwright
rehfeld wrote:

Code: Select all

^ї_a-zA-Z0-9ї:space:]-]+$
it matches any whitespace, not just a literal space
I should have known better... but hey, were all allowed to get stumped now and then..


thanks