David0603 All American 12764 Posts user info edit post |
How can I make a regular expression that has a character limit and will accept empty strings. I can successfully use {0,4} to set the character limit or I can successfully use * to have the regex accept empty string but I can not get them both to work together. 2/7/2008 2:44:57 PM |
synapse play so hard 60939 Posts user info edit post |
so you're saying that if you tell it to accept max 4 characters, that it won't accept an empty string? bc unless you tell it not to, i think it would accept empty strings by default
http://regexlib.com/ http://www.regexbuddy.com/] 2/7/2008 3:21:24 PM |
synapse play so hard 60939 Posts user info edit post |
ValidationExpression="^.{0,4}$"
works fine for me] 2/7/2008 3:33:18 PM |
David0603 All American 12764 Posts user info edit post |
What's ^. do? 2/7/2008 3:34:30 PM |
qntmfred retired 40726 Posts user info edit post |
^ means beginning of line . means any character other than new line 2/7/2008 3:36:44 PM |
David0603 All American 12764 Posts user info edit post |
Hmmm, maybe I should just give you my whole expression. This works great except won't work with an empty string.
(^[a-zA-Z0-9%\\s\\-]{0,4}$) 2/7/2008 3:39:30 PM |
synapse play so hard 60939 Posts user info edit post |
i think the brackets [] are requiring a single character, matching the a-z A-Z 0-9 specs you provided.
what kind of field are you trying to validate?
and from the sound of it, you don't want to require any characters, but if they do put some in, you only want them to be able to put 4 in, and whatever they enter must match the specs? ] 2/7/2008 3:51:06 PM |
David0603 All American 12764 Posts user info edit post |
Right, that's why I need to implement the star. This works great except there is no character limit. (^[a-zA-Z0-9%\\s\\-]*$) 2/7/2008 3:52:59 PM |
David0603 All American 12764 Posts user info edit post |
Damn you and your ghost edits. I think the guy wants the field to accept empty strings, all upper and lowercase letters, all numbers, hyphens, spaces and a max length of 25. I just used 4 b/c I got tired of typing out 25 chars every time to test.
[Edited on February 7, 2008 at 3:55 PM. Reason : ] 2/7/2008 3:55:19 PM |
David0603 All American 12764 Posts user info edit post |
Quote : | "ValidationExpression="^.{0,4}$"
works fine for me" |
What program did you use to test?2/7/2008 5:29:06 PM |
Noen All American 31346 Posts user info edit post |
(^[a-zA-Z0-9%\\s\\-]{0,25}$)
should give you exactly what you described. 2/7/2008 6:06:50 PM |
synapse play so hard 60939 Posts user info edit post |
^^ visual studio 2005...with what i gave you as part of an asp control] 2/7/2008 6:36:10 PM |
clalias All American 1580 Posts user info edit post |
nevermind didn't read the other posts.
[Edited on February 7, 2008 at 6:55 PM. Reason : .] 2/7/2008 6:55:04 PM |
David0603 All American 12764 Posts user info edit post |
^^^
That won't accept empty strings. Maybe its a bug in the code generators we use. Can someone test that for me? 2/8/2008 9:19:28 AM |
David0603 All American 12764 Posts user info edit post |
Shit, I tested it outside our application and it works. Stupid code generators. Thanks guys. 2/8/2008 9:27:02 AM |
DirtyMonkey All American 4269 Posts user info edit post |
If you need to test regular expressions this is a handy site: http://www.regular-expressions.info/vbscriptexample.html (VB) or http://www.regular-expressions.info/javascriptexample.html (JavaScript) 2/8/2008 9:42:40 AM |
David0603 All American 12764 Posts user info edit post |
Yeah, I found the second site and tested in there. 2/8/2008 10:48:12 AM |