From this site, I learned the algorithm is based on the Luhn Algorithm
public class IsraeliIDAttribute : ValidationAttribute { public override string FormatErrorMessage(string name) { return base.FormatErrorMessage(name); } public override bool IsValid(object value) { string id = value as string; if (!Regex.IsMatch(id, @"^\d{5,9}$")) return false; // number is too short - add leading 0000 if (id.Length < 9) { while (id.Length < 9) { id = '0' + id; } } //validate int mone = 0; int incNum; for (int i = 0; i < 9; i++) { incNum = Convert.ToInt32(id[i].ToString()); incNum *= (i % 2) + 1; if (incNum > 9) incNum -= 9; mone += incNum; } if (mone % 10 == 0) return true; else return false; } }Usage:
public class MyModel { [IsraeliIDAttribute(ErrorMessageResourceName = "InvalidId", ErrorMessageResourceType = typeof(Validations))] public String ID { get; set; } }
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeletepython Training institute in Pune
python Training institute in Chennai
python Training institute in Bangalore
A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
ReplyDeleteData Science course in kalyan nagar
Data Science course in OMR
Data Science course in chennai
Data science course in velachery
Data science course in jaya nagar
Data Science interview questions and answers
This comment has been removed by the author.
ReplyDeleteI am looking for and I love to post a comment that "The content of your post is awesome" Great work!
ReplyDeleteDevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery
Tho coding is really simple.It is working.Thank you. Java training in Chennai | Certification | Online Course Training | Java training in Bangalore | Certification | Online Course Training | Java training in Hyderabad | Certification | Online Course Training | Java training in Coimbatore | Certification | Online Course Training | Java training in Online | Certification | Online Course Training
ReplyDelete
ReplyDeleteNice blog! Thanks for sharing this valuable information
Reasons to learn Java
Top Reasons to learn JAVA
This post is so interactive and informative.keep update more information...
ReplyDeleteAndroid Training in Tambaram
Android Training in Chennai
Great post. keep sharing such a worthy information.
ReplyDeleteSwift Developer Course in Chennai
Swift Training in Bangalore
Swift Online Course
Mindblowing blog very useful thanks
ReplyDeleteDevOps Training in Porur
DevOps Training in Chennai
Great post. keep sharing such a worthy information.
ReplyDeleteData Science Course in Chennai