Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I solve this problem ? : At least one numeric character allowed without regex

if(password.search(/[0-9]/)){
    document.getElementById('fpasswords').innerHTML="*atleast one numeric character";
    return false;
}

here i used regex but i don’t want to use it so what’s the solution?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can check each character with the function isNaN, this function returns false is it’s a numeric character and true if it’s not:

const str = 'Papayas1';

for (var i = 0; i < str.length; i++) {
  
  if(!isNaN(str.charAt(i))) console.log('this is a number')
  else console.log('this is not a number')
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading