帮助我屏蔽罗马数字的输入掩码。我需要创建一个掩码,用它我只能输入从I到X的罗马数字
发布于 2012-11-27 04:10:12
如果您不使用插件,最简单的方法是编写一个正则表达式,并根据它匹配一个输入值。如果找到一个非常非常好的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");
}
});对于数字1-10,只需使用以下正则表达式:
/^(IX|IV|V?I{0,3})$|^X$/ghttps://stackoverflow.com/questions/13572104
复制相似问题