PC Review


Reply
Thread Tools Rate Thread

Regular Expression required

 
 
Sathyaish
Guest
Posts: n/a
 
      6th Sep 2005
RegEx heros,

I want to validate a certain field such that it shouldn't contain the
percentage character (%) or the asterisk character symbol (*). The
specification is that:

(1) The field must not contain the percentage symbol; AND
(2) The field must not contain the asterisk symbol.

It should contain neither of them. Can you please help me with the
RegEx for this?

 
Reply With Quote
 
 
 
 
Damien
Guest
Posts: n/a
 
      6th Sep 2005
Sathyaish wrote:
> RegEx heros,
>
> I want to validate a certain field such that it shouldn't contain the
> percentage character (%) or the asterisk character symbol (*). The
> specification is that:
>
> (1) The field must not contain the percentage symbol; AND
> (2) The field must not contain the asterisk symbol.
>
> It should contain neither of them. Can you please help me with the
> RegEx for this?


Sounds dangerous - wouldn't it be better to scan the field for only
valid characters. Or is every possible character valid except for * and
%? Sounds a bit unusual.

^([^*%]|\n)*$

Damien

 
Reply With Quote
 
Oliver Sturm
Guest
Posts: n/a
 
      6th Sep 2005
Damien wrote:

>Sounds dangerous - wouldn't it be better to scan the field for only
>valid characters. Or is every possible character valid except for * and
>%? Sounds a bit unusual.
>
>^([^*%]|\n)*$


When we're talking about a field, I wouldn't assume that a complete line
is meant; so I think the \n shouldn't be an option here. Also, if the
field is being scanned in the context of a complete line of text (ie,
standing between other fields), the line start and end markers would have
to be left out. Just my personal preference, of course, but I would have
given the example as

[^*%]+

This makes no assumptions whatsoever, apart from the fact that the field
should be comprised of at least one character that's not a * or a %.
Obviously, if the OP would be using the expression in a larger context, it
would have to be modified accordingly.

And I second the notion that it's unusual to exclude only these two
characters in what sounds like a query string to me :-)


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression AND required validator together? Keith G Hicks Microsoft ASP .NET 9 22nd Feb 2008 12:09 AM
Regular Expression required Sathyaish Microsoft ADO .NET 1 6th Sep 2005 09:40 PM
Regular Expression required Sathyaish Microsoft VB .NET 2 6th Sep 2005 12:53 PM
Regular Expression Regex/Match fails if regular expression returns a null tdmailbox@yahoo.com Microsoft C# .NET 1 31st May 2005 03:19 AM
Regular Expression / Required Field Validator John . Microsoft ASP .NET 5 23rd Mar 2005 05:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:59 AM.