If you can't use expression forces Java Script to do type coercion on your input value; it must first be interpreted as a number for the subtraction operation.
If that conversion to a number fails, the expression will result in result is then compared to the original value you passed in.
Note: If you are using WPF, I don't think there is a Masked Text Box in the base libraries, however there are extensions available on Nu Get which may provide similar functionality. It gives you a true/false value, but doesn't give any real validation. I added the code to the if statement to better explain. Try Parse as davenewza recommended, but another alternative is to use the Visual Basic Is Numeric function from C#.
(Also, for the telephone number example used in the original question, it may not be sufficient: it'll return false for symbols and whitespace that might be in a typical phone number input.)@Dan Puzey In his example he wrote specifically: if (txt Home Phone.
So far, I've checked that the Textbox has something in it, but if it has a value then it should proceed to validate that the entered value is numeric: Here's a solution that allows either numeric only with a minus sign or decimal with a minus sign and decimal point.
You should I can't believe no one pointed out the use of a regular expression (replace) after warning about not using regular expressions...However, there's a special rule that says , and so a value that can't be converted to a number (and only values that cannot be converted to numbers) will result in false.The check on the length is for a special case involving empty strings.One feature is that Finite(Infinity) // false Finite(Na N) // false Finite(-Infinity) // false Finite(0) // true Finite(2e64) // true Finite('0') // false Finite(null) // false While this code snippet may solve the question, including an explanation really helps to improve the quality of your post.Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.