Home > Net >  C # asp.net with regular expressions and validation controls validation text box value is not empty
C # asp.net with regular expressions and validation controls validation text box value is not empty

Time:09-28


I use the following code to test whether TEXTBOX1 input character is digital

 
The Regex r=new Regex (" [0-9] ");

if (! R.I sMatch (enclosing TextBox1. Text))
{
Response. Write (" & lt; Script language=javascript> Alert (' can only input Numbers! ') & lt;/script>" );
return;
}


1, when I input the insert one or more space between the two Numbers, input "1 3", for example, the regular expression to check out,
2, when I enter the characters as follows: DG123, couldn't check the regular expression,

How to solve?

CodePudding user response:

^ ((+ -))? 1 \ d + (\ d +)? $

CodePudding user response:

In turn, check for non-numeric
Regex. Match (TextBox1. Text, \ "D"), on the Match that do not conform to the requirements,

CodePudding user response:

^ ((+ -))? \d+(\.\d+)? $
  •  Tags:  
  • C#
  • Related