[thelist] ASP - Regular Expressions
Frank
lists at frankmarion.com
Tue Aug 5 11:39:58 CDT 2003
At 03:20 AM 2003-08-05 -0400, you wrote:
>I don't want the user to be able to input '--text' or 'text--' but able to
>input 'te-xt'.
>
>At the moment this is working properly for everything but 'text--'. It
>still allows the user to do this. I don't really know why except that it
>relates to the $ sign, because I first read about regular expressions today.
The following will accept any alpha-numeric (or dashes) that is not
preceded or followed by one or more dashes. If there is not one or more
matches, it will fail-- test failed.
^([^-]*[a-zA-Z0-9-][^-]*)+$
^ line start
[1] repeat at least 1 time
(
[^-]* Any character that is not a dash
[a-zA-Z0-9-] Any upper or lower case alpha-num or dash
[^-]* Any character that is not a dash
)+
[/1]
$ line end
Because this is all grouped, it's treated as a single unit. if you were to
remove the brackets, each [expression] would be considered one character.
--
Frank Marion lists at frankmarion.com Keep the signal high.
More information about the thelist
mailing list