Validation on multiple controls with regex

How do I validate multiple textbox's with regex.
Like Validate one textbox for curency & another for AlphaNumeric.
u2envy1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anurag ThakurTechnical ManagerCommented:
its a windows application or a web
in case of web application you will have to add a regularexpressionvalidator for every control and give a customized regular expression

in case of a windows application you will have to validate manually before you save the data
0
u2envy1Author Commented:
Windows.....
I got this for currency but its not working.

 static public bool IsCurrency(String strToCheck)
        {
            Regex objCurrencyPattern = new Regex(@"^\$?[0-9]+(,[0-9]{3})*(\.[0-9]{2})?$");
            return !objCurrencyPattern.IsMatch(strToCheck);
            //^\$?[0-9]+(,[0-9]{3})*(\.[0-9]{2})?$
            //[^a-zA-Z0-9]
        }
0
Anurag ThakurTechnical ManagerCommented:
what is your requirement for the currency...
i am not too good with regular expresions but i will give it a try if you can give me your requirements for the currency?
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

u2envy1Author Commented:
It can contain any number 0-9 but must have two decimal places at the end.
9999.99
0
Anurag ThakurTechnical ManagerCommented:
"^\d{0,4}(\.\d{2})?$"
0
u2envy1Author Commented:
If i add 23.25 it does not take it.
This is the format #######.## It could be less but not more.
0
Anurag ThakurTechnical ManagerCommented:
the previous expression was able to take 22.22 but was also taking 22 without any decimal places which i think is not your requirement
i have modified the expression a little "^\d{0,4}\.\d{2}?$"
hth ragi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anurag ThakurTechnical ManagerCommented:
my code snippet that works

<asp:ValidationSummary ID="vsPrice" runat="server" DisplayMode="BulletList" ValidationGroup="Price" />
<asp:TextBox ID="txtServicePrice" runat="server" MaxLength="10" Text="0.0"></asp:TextBox>
<asp:RegularExpressionValidator ID="revServicePrice" runat="server" ControlToValidate="txtServicePrice" Display="dynamic" ErrorMessage="error" SetFocusOnError="true" Text="*" ToolTip="error" ValidationExpression="^\d{0,4}\.\d{2}?$" ValidationGroup="Price"></asp:RegularExpressionValidator>
<asp:Button ID="btnPriceAdd" runat="server" OnClick="Button_Click" Text="Add" ValidationGroup="Price" />

Open in new window

0
u2envy1Author Commented:
Im using this on a windows form & not asp.net. I will try it again & let you know.
0
Anurag ThakurTechnical ManagerCommented:
the regular expression will work whether its a win form or a web form
0
u2envy1Author Commented:
I had to dive in & learn Regex & its special characters. This is what I came up with & it works.
Thx thou....

^[0-9]*(\.?[0-9]{2})$
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.