468,101 Members | 1,399 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

Are you a RegEx bandido?

Its not that I hate RegEx its that I have to relearn the same stuff every
couple of months because I forget what I last learned. Common eh? So... I'm
working on an expression to validate a MIME Type and I have a fairly decent
pattern set up but it needs some work...

<%--
MIME Type
match: type/name
match: type/name5
match: type/x-name
match: type/x-name-name
match: type/x-name+name
match: type/x-name_name
match: x-type/name

fail: type-/name
fail: type/name-
fail: type//name
fail: type_type/name
ValidationExpression="^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+-?\+?\.?_?[a-zA-Z0-9]+)+$"
--%>
<asp:RegularExpressionValidator
ID="Validator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Invalid MIME Type Format"
Display="Dynamic"
Font-Bold="true"
SetFocusOnError="true"
ValidationExpression="^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+-?\+?\.?_?[a-zA-Z0-9]+)+$"
/>

That part of the string that follows the / character allows a single
instance of one of the following characters multuple times [-?|+?|.?|_?] but
the problem is I don't know how to prevent two such allowable characters to
preceed or follow one another...

// currently matched but this pattern needs to fail
type/x-.name
// currently matched but this pattern needs to fail
type/x.-name

Got any idea how to express this rule?

Oct 16 '08 #1
2 1111
What about:

^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+[-+_\.]?[a-zA-Z0-9]+)+$

I am not familliar with the rules for mime type syntax, but this should
return valid results for the examples you have provided.
Oct 16 '08 #2
Yup good point; add another class...
[-\+_\.]?

"A Nonymous" <an*******@hotmail.comwrote in message
news:Xn*********************************@207.46.24 8.16...
What about:

^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+[-+_\.]?[a-zA-Z0-9]+)+$

I am not familliar with the rules for mime type syntax, but this should
return valid results for the examples you have provided.
Oct 17 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tim Conner | last post: by
20 posts views Thread by jeevankodali | last post: by
17 posts views Thread by clintonG | last post: by
6 posts views Thread by Extremest | last post: by
7 posts views Thread by Extremest | last post: by
3 posts views Thread by aspineux | last post: by
15 posts views Thread by morleyc | last post: by
reply views Thread by Karch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.