I have found a Regex that test if the text passed to a TextBox is an email.
If Regex.IsMatch(email.Text, "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" + "(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$") _
Then
// True
End If
I want to change this, so it will test if the text typed is just Numbers ?
How can I do that ?
If you want to make sure the text contains only digits use a simple
^\d+$or^\s*\d+\s*$to allow some spaces at the beginning and end.To allow negative numbers:
^-?\d+$or^[+-]?\d+$to allow numbers like+12For decimal numbers:
^[+-]?\d+(\.\d+)?$(this will allow0.54but not.54)This one will allow things like
.54