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
Asked
Active
Viewed 544 times
0
-
Do you have a plugin for validation? – nirazul Nov 26 '12 at 19:58
-
2In this case, it's probably easiest to test against all ten valid values. – Blazemonger Nov 26 '12 at 20:01
-
thanks, dropdown is the best way! – Александр Брус Nov 27 '12 at 06:45
1 Answers
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