I need to validate a phone number in javascript. The requirements are:
they should be 10 digits, no comma, no dashes, just the numbers, and not the
phone = phone.replace(/[^0-9]/g, ''); if(phone.length != 10) { alert("not 10 digits"); } else { alert("yep, its 10 digits"); }
This will validate and/or correct based on your requirements, removing all non-digits.