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
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 defaulthttp://regexlib.com/http://www.regexbuddy.com/]
2/7/2008 3:21:24 PM
ValidationExpression="^.{0,4}$"works fine for me]
2/7/2008 3:33:18 PM
What's ^. do?
2/7/2008 3:34:30 PM
^ means beginning of line. means any character other than new line
2/7/2008 3:36:44 PM
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
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
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
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
2/7/2008 5:29:06 PM
(^[a-zA-Z0-9%\\s\\-]{0,25}$)should give you exactly what you described.
2/7/2008 6:06:50 PM
^^ visual studio 2005...with what i gave you as part of an asp control]
2/7/2008 6:36:10 PM
nevermind didn't read the other posts.[Edited on February 7, 2008 at 6:55 PM. Reason : .]
2/7/2008 6:55:04 PM
^^^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
Shit, I tested it outside our application and it works. Stupid code generators. Thanks guys.
2/8/2008 9:27:02 AM
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
Yeah, I found the second site and tested in there.
2/8/2008 10:48:12 AM