Regular Expressions

  • Thread starter Thread starter Scott Natwick
  • Start date Start date
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
 
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!
 
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
 
Back
Top