Check for text field (no spaces)

I have a web page in which I have a text field, my requirement is: I do not want to allocate space in the text field, if the user gives space in the text field, it indicates the absence of a space in the text field

+3
source share
3 answers

If you want to write a value where spaces are not a valid character, you can use 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" />

"hello world" " ", , "helloworld" "database" . RequiredFieldValidator , , RegularExpressionValidator .

ControlToValidate.

+8

RegularExpressionValidator:

<asp:TextBox runat="server" ID="txt1" />
<asp:RegularExpressionValidator 
  runat="server" ErrorMessage="Spaces are not permitted" 
  ControlToValidate="txt1"
  ValidationExpression="[^\s]+" />

[^\s]+ " , ". , - , .

+1

, , .

<asp:TextBox runat="server" ID="txttitlename" />
<asp:RegularExpressionValidator runat="server" ErrorMessage="Spaces are not acceptable" ontrolToValidate="txttitlename" ValidationExpression="[^\s]+" />
0
source

Source: https://habr.com/ru/post/1720150/


All Articles