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
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.
You can use the RegularExpressionValidator control:
<asp:TextBox runat="server" ID="txt1" />
<asp:RegularExpressionValidator
runat="server" ErrorMessage="Spaces are not permitted"
ControlToValidate="txt1"
ValidationExpression="[^\s]+" />
The pattern [^\s]+ means "one or more characters that is not a space". So if any of the characters is a space, it will fail.
It might help you all
to remove your spaces in your document please try It.
<asp:TextBox runat="server" ID="txttitlename" />
<asp:RegularExpressionValidator runat="server" ErrorMessage="Spaces are not acceptable" ontrolToValidate="txttitlename" ValidationExpression="[^\s]+" />
You can use HTML page or Asp.Net page
only pattern="[^\s]+" in side TextBox
<input id="Text1" pattern="[^\s]+" type="text" />
Related
I have a field that required 3 different validators:
RequiredFieldValidator, RegularExpressionValidator, and CompareValidator.
Each validator has a "*" to show that something is wrong with the input:
<asp:TextBox ID="txtAddMin" runat="server" Width="30%" MaxLength="2"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Min Value is missing" ControlToValidate="txtAddMin" ForeColor="Red" ValidationGroup="vgBinAdd">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ErrorMessage="Invalid Min Value Entered" ControlToValidate="txtAddMin" ForeColor="Red" ValidationGroup="vgBinAdd" ValidationExpression="^[0-9]{2}$">*</asp:RegularExpressionValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtAddMin" ControlToCompare="txtAddMax" Operator="LessThan" Type="Integer" ErrorMessage="Min Value shoule be less then MaxValue" ForeColor="Red" ValidationGroup="vgBinAdd">*</asp:CompareValidator>
Validations work as expected, however, when failing, the "" is displayed in different positions. So, when CompareValidator fails, the "" is displayed a few spaces from the input field.
Basically, every validator takes up some space after the input field and "*" is displayed with extra space before it based which validator fails.
IS that possible to fix that, so, the start is displayed in the fix position no matter which validator fails?
i have a textbox that will only accpet numbers, so i have to make validator that accept only number except 0, what's the regular expression i should do, any help please, i have already try this :
<asp:RegularExpressionValidator ID="regValSummary" runat="server"
ControlToValidate="txtSummary" Display="Dynamic" ValidationExpression="[1-9]*"
ValidationGroup="grpLigneComande">
*
</asp:RegularExpressionValidator>
any suggestion please !!
You can use Compare Validator instead of RegularExpressionValidator like
<asp:CompareValidator ID="CompareValidator1" runat="server" ValueToCompare="0" ControlToValidate="TextBox1"
ErrorMessage="Must enter positive integers" Operator="GreaterThan" Type="Integer"></asp:CompareValidator>
Hope this will help.
i think a RegularExpressionValidator won't be able to help you. Try exploring MaskedTextBox. C# Numeric Only TextBox Control
Or if you're using Ajax Control Toolkit, try the FilteredTextBoxExtender, using a sample MobileNo textfield which will accept numbers except 0:
<asp:TextBox ID="txtMobileNo" runat="server" CssClass="textBox" Width="200px" MaxLength="15" />
<ajax:FilteredTextBoxExtender runat="server" ID="FilteredTextBoxExtender4" TargetControlID="txtMobileNo" FilterMode="ValidChars" FilterType="Numbers, Custom" ValidChars="+-" InvalidChars="0" />
I am getting the above error. I want to validate the textbox which allow some special characters but not letters and numbers. For that I wrote the below code but it is giving the above error.
The code
<asp:TextBox ID="txtTag" runat="server" Width="250"></asp:TextBox>
<asp:RegularExpressionValidator ID="reg1" runat="server"
ControlToValidate="txtTag" ErrorMessage="*" Text="please check"
ValidationExpression="/^[[\]'/\\# &(){}+$%#=~"-`/*.&]([[\]'/\\# &(){}+$%#=~"-`/*.&]*)$/" />
What am I doing wrong?
Escape the quotes in the ValidationExpression with ":
ValidationExpression="/^[[\]'/\\# &(){}+$%#=~"-/*.&]([[]'/\# &(){}+$%#=~"-/*.&]*)$/"
They collide with the outer quotes otherwise.
Use
/^[[\]'/\\# &(){}+$%#=~"-/*.&]([[]'/\# &(){}+$%#=~"-/*.&]*)$/
as ValidationExpression.
In web application, i am using regular expression for date like "dd-mm-yyyy" format for this i get the validation but it is not working when we enter date like "12-02-2012" remaining condition it is working fine, can you help me this is my validation expression.
<asp:RegularExpressionValidator ID ="myg" runat ="server" ControlToValidate ="txt" ErrorMessage ="Check"
ValidationExpression ="^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$" >
</asp:RegularExpressionValidator>
I solve the problem,
ValidationExpression ="^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[123456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"
asp:RegularExpression is not the way to do this.
For validating date using an ASP.NET Validator its ideal to use asp:CompareValidator
Here is a small mock-up
<asp:TextBox ID="txtDatecompleted" runat="server"/>
<asp:CompareValidator ID="dateValidator" runat="server"
ControlToValidate="txtDatecompleted"
ErrorMessage="Please enter a valid date."
Operator="DataTypeCheck"
Type="Date"
ValidationGroup="TestVGroup">
</asp:CompareValidator>
<br />
<asp:Button ID="ClickButton" Text="Click Me" runat="server"
ValidationGroup="TestVGroup"
OnClick="ClickButton_Click" />
This will automatically check for different date formats and leap years
I slove the problem,
ValidationExpression ="^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|
((0[1-9]|[12]\d|30)-(0[123456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])
\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|
((16|[2468][048]|[3579][26])00))))$"
In my web application, I have a text box.
The user should enter a value of which the first character is a letter, not a digit, and the remaining characters can be alphanumeric.
How can I write regular expression to do this?
You can use: [A-Za-z]\w* to ensure the first character is a letter and any remaining characters are alphanumeric (optional by using the *)
<asp:RegularExpressionValidator ID="rev" runat="server"
ControlToValidate="txtBox"
ErrorMessage="First character must be a letter!"
ValidationExpression="[A-Za-z]\w*" />
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtBox"
ErrorMessage="Value can't be empty" />
The RequiredFieldValidator is used in conjunction with the RegularExpressionValidator to prevent blank entries. If that textbox is optional, and only needs to be validated when something is entered, then you don't have to use the RequiredFieldValidator.
<asp:TextBox id="TextBox1" runat="server"/>
<asp:RegularExpressionValidator
ControlToValidate="TextBox1"
ValidationExpression="^[A-Za-z]\w*"
ErrorMessage="Input must start with a letter"
runat="server"/>