I am creating an input mask used for the length of the elements. This input is converted to the “correct” format when blurred, but it must accept numbers, decimal numbers, spaces, single quotes, double quotes and / for fractions (without letters).
Everything is fine with me, but I am not a master of regular expressions and I feel that my template is too complicated. Thus, the following values are valid:
5 6 (feet and inches separated by spaces)
5'6 "(feet and inches in the correct format)
5.2 6 (decimal feet separated by spaces)
5.2'6 "(decimal feet in the correct format)
5 6.1 (decimal inches separated by spaces)
5'6.1 "(decimal inches in the correct format)
5.2 6.1 (decimal feet and inches separated by spaces)
5.2'6.1 "( )
5 6 1/2 ( , )
5.2'6.1 1/2 "( )
78 "( )
78.4 "( )
, . -, , , ( , ). http://jsfiddle.net/t37m0txu/383/
var p_num = "[0-9]";
var p_range = "{0,9}";
var p_dec = "([.]{0,1})";
var p_space = "([ ]{0,1})";
var p_base = p_num + p_range + p_dec + p_space;
var p_afternum = "?(?=" + p_num + ")";
var p_quote = "(\'(0?" + p_base + ")?\|\"$)";
var ex = "(" + p_base + ")" + p_afternum + p_quote + "(0?" + p_base + ")?\""