Click here to Skip to main content
15,867,879 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want below javascript data validation for account number textfield.
Display error if enter all zero(s) ("0" and "00000" are the same thing)
Display error if enter all one(s)
Continue all the way:Display error if all nine(s)
Display Error if enter 123456789
Display Error if enter 987654321?

What I have tried:

I tried for single value but here requirements is different and i am beginner.
Posted
Updated 23-Jan-21 20:23pm
Comments
Patrice T 23-Jan-21 22:02pm    
Show your work.

You can do a regex check for "all digits the same":
^(\d)\1*$
But for the rest you are much, much better off checking the entered value against a list of valid account numbers = while you can very easily write javascript code to check for a rising or falling number sequence that doesn't eliminate accounts where two numbers have been swapped or "just typed wrong" - that's why credit card numbers and even bank account numbers include checksum data to validate "this is a correct account number and it's one of ours" without going to a database. Checking the checksum should eliminate all digits the same as well!

And that is the final and pretty much essential step: validate the account number against a list of "actual accounts" in a DB to be sure the number is correct, valid, and the account is not blocked, frozen, or closed.
 
Share this answer
 
You did it for one. So do a ton of statements that do each one

In general, go through a beginners course on Javascript, because even if I give you the answers, you won't learn by being given code, you will learn by doing exercises at your level. Until you can do basic tasks like this, you are not at the point of writing useful code, or code you could morally charge money for
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900