By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

How to validate a string with a Regular Expression?

P: n/a
Hi All,

I'm trying to find a way to validate a string variable in the code behind
with a regular expression. I know there are validator controls but these all
work with the ControlToValidate property and I don't have a control, just a
string variable.

Can anyone help me out?

TIA,
Friso Wiskerke
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Friso,

The validators as you describe it are in my opinion not code behind.

Can you tell something more what you want to achieve, because when you use
code behind you have to send information to that. And for that you use one
or the other control.

To say it in other words, somewhere should the information be typed in.

Cor
Nov 21 '05 #2

P: n/a
Cor,

The data that I'm trying to validate resides in a database. I writing code
that's validating the current data in the database, that's done by looping
through a datatable (or datareader) and check each row field by field.

When using a ValidatorControl you have to assign a control to it. Only
controls of type: TextBox, ListBox, DropDownList, RadioButtonList,
HtmlInputText, HtmlInputFile, HtmlSelect and HtmlTextArea can be assigned,
so I can't assign a DataColumn object or a string variable to it.

That's why I'm looking for a way to achieve some other kind regular
expression validation way in code-behind .

Cheers,
Friso
"Cor Ligthert" <no************@planet.nl> wrote in message
news:O$*************@TK2MSFTNGP11.phx.gbl...
Friso,

The validators as you describe it are in my opinion not code behind.

Can you tell something more what you want to achieve, because when you use
code behind you have to send information to that. And for that you use one
or the other control.

To say it in other words, somewhere should the information be typed in.

Cor

Nov 21 '05 #3

P: n/a
Friso,

I think that via this newsgroup it is to difficult to help you.

However on this pages is in my opinion bassicly your problem described.
Therefore look to this and maybe you can than ask question refering too
these pages.

http://samples.gotdotnet.com/quickstart/aspplus/

I hope this helps something

Cor
Nov 21 '05 #4

P: n/a
Finally found it searching through the namespaces !!

There's a function: System.Text.RegularExpressions.Regex.IsMatch() which
takes 2 parameters: "input" and "pattern". The first is the string to
validate, the seccond is the regular expression that the string is validated
against. The result is a boolean, True if it's a match.

Thanx,
Friso
"Cor Ligthert" <no************@planet.nl> wrote in message
news:#N**************@tk2msftngp13.phx.gbl...
Friso,

I think that via this newsgroup it is to difficult to help you.

However on this pages is in my opinion bassicly your problem described.
Therefore look to this and maybe you can than ask question refering too
these pages.

http://samples.gotdotnet.com/quickstart/aspplus/

I hope this helps something

Cor

Nov 21 '05 #5

P: n/a
"Friso Wiskerke" <fr***@pestaartje.nl> schrieb:
I'm trying to find a way to validate a string variable in the code behind
with a regular expression. I know there are validator controls but these
all
work with the ControlToValidate property and I don't have a control, just
a
string variable.


Take a look at 'System.Text.RegularExpression.Regex' and its 'IsMatch'
method. If you want to get all matches, use 'Matches'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

P: n/a
Friso,

I was thinking that you did not know how to get that string from the
clientside to the code behind.

Here a website for regulair expressions

http://www.regexlib.com/Default.aspx

Maybe that helps you making it.

Cor
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.