Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validation on textbox (no space)

Tags:

asp.net

i have a webpage in that i have a text box, my requirement is i don't want to give space in the textbox if user give space in textbox it give indication no space in the textbox

like image 860
Surya sasidhar Avatar asked Dec 23 '22 08:12

Surya sasidhar


1 Answers

If you intended to capture a value where spaces aren't a valid character, you could use a RegularExpressionValidator:

<asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="txtBox"
    ErrorMessage="Spaces are not allowed!" ValidationExpression="[^\s]+" />
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtBox" 
    ErrorMessage="Value can't be empty" />

This would prevent "hello world" and "data base" since they contain spaces, and would only allow "helloworld" and "database" as valid values. You must use a RequiredFieldValidator in conjunction with it to prevent blank entries since the RegularExpressionValidator does not prevent that on its own.

Specify the name of the textbox in the ControlToValidate property.

like image 91
Ahmad Mageed Avatar answered Jan 11 '23 08:01

Ahmad Mageed