javascript - Check if string has period (decimal) w/ jQuery? -
i need check if provided input user has decimal, say, "cannot convert decimals."
if(fldval.match(/^.+$/g)){ $("#fld").attr("placeholder", "cannot convert decimals.").val(""); // $("#fld").css("border-color", "#df4747"); $("#fld").toggleclass("error-animation"); $("#fld").addclass("error-color"); e.preventdefault(); } it displays error, says every input decimal. displays code though input not decimal (e.g., 75).
here jsfiddle :: http://jsfiddle.net/mvwvn/
use indexof instead of regex, :
if (fldval.indexof('.')!=-1) working jsfiddle
javascript jquery html
No comments:
Post a Comment