MVC Validation make RegularExpression numeric only on string field

The regular expression is wrong. Replace it with:

[Required]
[MaxLength(12)]
[MinLength(1)]
[RegularExpression("^[0-9]*$", ErrorMessage = "UPRN must be numeric")]
public string Uprn { get; set; }    

Don’t forget to include:

@Scripts.Render("~/bundles/jqueryval")

in your view for the jquery validation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)