简体   繁体   中英

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM