user2319241
user2319241

Reputation: 11

regular expression validation in asp.net

i am using Regular expression validator c# in asp.net for a login page..i have different login pages for student,lecturer and admin..the login ids are of the form 1RNxxCSxxx,1RNLECSxxx,1RNADCSxxx respectively(x-digits) my problem is it validates the text box and displays the error message.. but it still continues n logs in..my code is..

    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"       ControlToValidate="TextBox1" ErrorMessage="Enter in 1RNxxCSxxx format" ValidationExpression="[1][R][N][0-9][0-9][C][S][0-9][0-9][0-9]"></asp:RegularExpressionValidator>

ie..if i type lecturer id in student login page i can still login inspite of gettin error message..any help would be appreciated.thank u

Upvotes: 0

Views: 1336

Answers (1)

nerdybeardo
nerdybeardo

Reputation: 4675

It seems from the name of your textbox that you're using custom login logic. I would suggest you look into using a membership provider which will be more robust in securing your entire application. Check out How to configure member ship with a database other than aspnetdb

For your immediate problem though in the method that logs the user in check if the page is valid.

if( !Page.IsValid )
{
     return;
}

More information can be found here: this link

Also your regular expression is incorrect. Use the following for a successful match.

^1RN([0-9]{2}|LE|AD)CS[0-9]{3}$

The expression above says that the string should start (^ signifies a start) with 1RN have two digits or LE or AD followed by the letters CS and three digits ($ signifies end).

Upvotes: 1

Related Questions