0
votes

I am developing an MVC application and I have a requirement where there should be a instant client-side validation as soon as I enter a number in a textbox. So I need a regular expression to write as a validation on top of the property in model class for that field.

^[1-9]+[0-9]*00$ works for numbers divisible by 100 but am looking an expression which checks if the number divisible by 500. Can anyone help?

Here is the eg for model validation where it checks if a number is divisible by 100

[Required] [RegularExpression(@"^[1-9]+[0-9]*00$ ", ErrorMessage = "Number not divisible by 100")]

public string EmployeeNumber{ get; set; }

1
"there should be a instant client-side validation as soon as I enter a number in a textbox. So I need a regular expression" that is an absolutely false conclusion you just jumped to.Blindy
If it should be a regular expression and not arithmetics, ^[1-9]\d*[05]00$?Alexander Mashin

1 Answers

0
votes
^(?:[1-9]\d*[05]00|500|0)$

A number is divisible by 500 if it ends with 000 or 500.