Code for textbox validation for spaces

Posted by Rrana under ASP.NET on 9/26/2011 | Points: 10 | Views : 3315 | Status : [Member] | Replies : 6
Hi,

my task is to validate the text box with spaces. I need code for this.
Example in textbox= code for /////is valid

textbox=codefor /////invalid


thanks in advance

Sucharitha Goud
Bank Of America..



Responses

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

Up
0
Down
Hi,

I am not sure i am clear on your requirment. Use this regexp ^\s*[a-zA-Z\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: Rrana on: 9/27/2011 [Member] Starter | Points: 25

Up
0
Down
Exmaple user enter into textbox as "Hellohowareyou" ==========this is not valid

textbox as "hello how are you" ============this is valid.

i need to check the sentence.

Sucharitha Goud
Bank Of America..

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

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

Up
0
Down
Exmaple user enter into textbox as "Hellohowareyou" ==========this is not valid

textbox as "hello how are you" ============this is valid.

i need to check the sentence.

Sucharitha Goud
Bank Of America..

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

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

Up
0
Down
Hi,
I am not clear on your question. I tried "Hellohowareyou" , this is valid againt the given regexp. Please explain exactly what you want.

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

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

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

Up
0
Down
you can use ajax filtered textbox for this purpose. set filtertype as custom.

...

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

Login to post response