regular expression
-
Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'
-
Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'
one more method u can check enter value on server side or in page.
-
one more method u can check enter value on server side or in page.
try [.\-0000] in expression
-
Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'
This one worked for me:
System.Text.RegularExpressions.Regex.IsMatch(str, @"[.\-]\d*(0){4}");
when tested:
bool b1 = Do("10.0000"); //false
b1 = Do("10-0000"); //true
b1 = Do("10-0000/"); //true
b1 = Do("10-0000."); //true
b1 = Do("10-0000/-"); //truewhere
Do()
isprivate bool Do(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"[.\-]\d*(0){4}"); }
♫ 99 little bugs in the code, 99 bugs in the code We fix a bug, compile it again 101 little bugs in the code ♫
-
Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'
fififlowertot wrote:
when all the remaining characters are numbers
Not sure what you mean by that. However, the following regex will ensure the string ends with a dash followed by exactly 4 numeric digits.
-[0-9]{4}$
If you want to ensure the whole string is zero or more numeric digits followed by a dash followed by exactly 4 zeroes, this would work:
^[0-9]*-0{4}$
[
S<T>::f(U) // Out of line.
](http://msdn.microsoft.com/en-us/library/8yk3t00s(v=vs.71).aspx)