Regular Expressions

S

Scott Natwick

Can anyone suggest a good reference for Regular Expressions?

Or more specifically, I need to check that a user has made a selection from
Drop Down List. The default in my Drop Down List is "[Select a Model]". I
need a Regular Expression to trigger if this default value has not changed.

Any ideas?

Thanks in advance,
Scott Natwick
 
S

Scott Mitchell [MVP]

Scott said:
Can anyone suggest a good reference for Regular Expressions?

http://www.regexlib.com

There's also a focused email listserv, along with regex-focused blogs, at:
http://regexadvice.com/

Or more specifically, I need to check that a user has made a selection from
Drop Down List. The default in my Drop Down List is "[Select a Model]". I
need a Regular Expression to trigger if this default value has not changed.

I don't think you necessarily need a regular expression here. Why not
just use a RequiredFieldValidator?

From "ASP.NET controls make client-side validation a snap"
(http://builder.com.com/5100-6371_14-1052985-2.html):

"The Name and Favorite Color fields are both validated with
RequiredFieldValidator control. You’ve already seen how it can be used
to validate the contents of a TextBox, but what about a DropDownList
control? RequiredFieldValidator works by comparing the value of the
control it is validating against the value it holds internally in its
InitialValue property, which is an empty string (“”) by default. So as
long as a DropDownList’s initially selected item has a value that’s
equal to the InitialValue property of its associated
RequiredFieldValidator, everything will work as expected. You can see
this in action in the code snippet below:

ColorValidator.ControlToValidate = cboColor.ID;
ColorValidator.ErrorMessage = "Please pick a color";
ColorValidator.InitialValue = cboColor.SelectedItem.Value;
"

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
K

Kannan Meiappan

Hi,

Actually you don't have to use regular expression for checking whether a user has made a selection or not in a dropdown...Instead, you can use RequiredFieldValidator....Just check the code below...

<asp:dropdownlist id="ddl" runat="server" CssClass="SelectBox"></asp:dropdownlist>
<asp:requiredfieldvalidator id="RFVddl" runat="server" InitialValue="0" ErrorMessage="Please Select " ControlToValidate="lstUserType" Text="*" />

If you have asssigned a value of "0" to "[Select a Model]", which is default selection in your dropdown, then assign that "0" to initialvalue property of RequiredFieldValidator. This will solve your problem.....


Regards,
Kannan Meiappan
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,159
Latest member
SweetCalmCBDGummies
Top