simple regex?

J

Jerry

I know this is too easy, but I am not getting it. I want to regex string to
find any string that has non numeric characters, integers and floats
verification basically.



I am using the following:




!Regex.IsMatch( varValue, @"(\b[^A-Za-z\\.]*\b)" )



To filter through a basic list of data and results:



Data Results

=================================

"3174.00" pass

"435015" pass

"15" pass

" SQ. TUBING .065" fails

"20" pass

"248" pass

"1/2" fails

"0.00" pass

"G" fails

"01/31/06" fails

"ST-1020" fails

"Foot" fails

"16.533" pass



Thanks,



Jerry
 
O

Oliver Sturm

Hello Jerry,

I suggest you use positive verification, if at all possible - it's usually
much easier to define and clearer in its purpose than negative
verification. This is an integer:

\d+

And this is a float:

\d+\.\d+

(Note that the decimal separator depends on the locale that was used to
output the data.)

You can combine these two expressions:

\d+|\d+\.\d+

Or you can make part of it optional:

\d+(\.\d+)?

So it would be really easy to match exactly those of your entries that are
valid by your definition - everything else is, by definition, not valid.


Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top