code for alphanumeric with spaces validation

Posted by Rrana under JavaScript on 9/26/2011 | Points: 10 | Views : 6598 | Status : [Member] | Replies : 3
Hi,

i need code for alphanumeric with spaces and characters with spaces validation for textboxes.


Thanks in advance

Sucharitha Goud
Bank Of America..



Responses

Posted by: Blessyjees on: 9/26/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Use this regexp ^\s*[a-zA-Z0-9\s]+\s*$ to validate your textcode

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mdjack on: 9/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

Try this,

I could noe understand ur requirement. Their are two ways to validate the Controls they are 1. Client-Side Validation and 2. Server-Side Validation.

1. Client Side Validation: using the Required Field Validator and RegularExpression Validator. the following sample code is help ful for u.
<asp:TextBox ID="txtAddress1" Text="" size="30" MaxLength="100" CssClass="Black08" runat="server"/>
<asp:RequiredFieldValidator ID="rfvAddress1" runat="server" ControlToValidate="txtAddress1"
ErrorMessage="Please enter ADDRESS (1)" ForeColor="Red" ValidationGroup="Group1"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revAddress1" runat="server" ErrorMessage="Enter valid ADDRESS (1)"
ControlToValidate="txtAddress1" ForeColor="Red" ValidationExpression="^((?:[A-Za-z0-9-'.,\s]+|&[^#])&?)$"
Display="Dynamic"></asp:RegularExpressionValidator>

2. Server-Side Validation using the Regex class Expression
if (!string.IsNullOrEmpty(txtAddress1.Text))
{
if (!Regex.IsMatch(txtAddress1.Text.Trim(), @"^([\w\d\s\-\'\.\,]*)$"))
{
revAddress1.IsValid = false;
revAddress1.ErrorMessage = "Enter valid ADDRESS(1)";
}
else
{
revAddress1.IsValid = true;
}

N. MOHAMED ZACKKARIAH

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vkrishna on: 11/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hello Blessyjees,

Thanks your regualr expression worked for me.

Thanks again

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response