Reputation: 401
i need a regular expression for checking numbers , allowing 'null' value and not allowing whitespasces;
in CustomerViewModel:
[Display(Name = "Phone")]
[RegularExpression(@"^[0-9]{4,15}", ErrorMessage = "{0} is not correct!")]
public string CustomerPhoneNumber { get; set; }
it allows numbers and 'null' value and " ". in editing mode of form, when my textbox has " " ,it does not show error! i want to show error for " " and stop posting form. how can i do that?
Upvotes: 0
Views: 1769
Reputation:
for allowing numerical and "null" value.*provided null is in lower-case and null is a word.
([0-9a-z]+)
for allowing only numerical
([0-9]+)
Upvotes: 0
Reputation: 354
This should work for allowing only numbers without spaces
^(\s*|\d+)$
Upvotes: 1