0

Help me with masked input mask for roman numeral. I need to create a mask with which I can input only roman number from I to X

1 Answers1

1

If you don't use a plugin, the easiest way is to write a regex and match an input value against it. If found a really really nice one here

$(function(){
    var strInput = $('input#myRomanInputField').val();
    var matchArr = strInput.match(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/g);
    console.log(matchArr);
    if(matchArr) {
        // test successful
        console.log("true");
    } else {
        // failure
        console.log("false");
    }
});

For numbers 1-10, just use this regex:

/^(IX|IV|V?I{0,3})$|^X$/g
Community
  • 1
  • 1
nirazul
  • 3,928
  • 4
  • 26
  • 46