-4

I want to validate the Adhara card number.Data type in my view model is Long. max and minilength validation throws a error like"int64 cannot be converted into array"

Range validator

[Range(100000000000,999999999999,Error message="Enter Correct Aadhar number")
    public long? Aadharnumber { get; set; }

range is working for me.but do we have any other method to represent this validation

  • How have you tried validating it? Show your code and explain exactly what issue you are having. Please take a second to read https://stackoverflow.com/help/mcve – Alexander Higgins Jul 17 '17 at 06:32

1 Answers1

0

What you need is a regular expression based validation. Basically, you need to have an annotation for validating the field. Something like this - [RegularExpression("[^0-9]", ErrorMessage = "Some error message here")]

Refer the following questions for some more details - DataAnnotations validation (Regular Expression) in asp.net mvc 4 - razor view MVC Validation make RegularExpression numeric only on string field

You will have to figure out the correct regular expression for your validation and use it similar to the examples shown above. Additionally, can all adhar numbers be represented as long? Is it better to handle it as a string instead?

ArunGeorge
  • 495
  • 5
  • 11
  • you are right.but i have service and respository.if a person enter single value(after entering all 12 string) .it will throw some error at service.so i don't want to make it string. – sai krishnan Jul 17 '17 at 07:06
  • and also my maximum value is 12 and minimum value is also 12.how regular express will work? any suggestion or answer – sai krishnan Jul 17 '17 at 07:09