I am trying to convert regular expression format into a mask-input string to guide the user to enter the correct input on the UI. Numbers would be represented by "#" and letter by "A".
Basically,
"^\d{3}$" --> "###"
"^(GB)\d{3}$" --> "GB###"
"^\d{2}\.\d{3}\/\d{4}-\d{2}$" --> "##.###/####-##"
"^\d{2}[ ]\d{3}[ ]\d{3}$" --> "## ### ###"
function convertToMaskInput(regex){
}
convertToMaskInput("^\d{4}$");
//Output: "####"
I am beginner to Javascript and I am having hard time to do this dynamically. Any help or guidance is appreciated.
Thanks in advance!
/^\d{3}$/--> "###"/^(GB)\d{3}$/--> "GB###"/^\d{2}\.\d{3}\/\d{4}-\d{2}$/--> "##.###/####-##"/^\d{2}[ ]\d{3}[ ]\d{3}$/--> "## ### ###"MaskedInput-components are capable of doing.