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

html input with javascript . adding

When the date of birth is entered in my input, I want a full stop after 2 characters are entered automatically. I know it’s done with toLocaleLowerCase

Sample:
01011980

Output:
01.01.1980

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

>Solution :

If the sample is always fixed length which I guess it is, you can do it like this:

var sample = '01011980';

function processString(inputString){
    return inputString.substr(0,2)+'.'+inputString.substr(2,2)+'.'+inputString.substr(4,4);
    
}

output = processString(sample);

alert(output);
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