3
I have a code that gets a value from an HTML field. I match the value of a variable to the object in jQuery, and then use the value placed there to make some comparisons of >=
or <=
.
I want to put a zip code mask on the spot, but the dash (99999-999
) cuts the numerical value of the zip code to the first 5 digits. I made the following code so that I could take that trace out of play and only mess with the ZIP code numbers, but for some reason it doesn’t work:
var cep = parseInt($('#ip-cep').val.toString().replace(/-/, ''), 10);
Just to clarify, I take the value of the HTML field, turn it into string, remove the trace with .replace()
, and then convert back into numeral to make the comparisons.
The point is it doesn’t work. The value of cep
always returns as NaN
, even with input only numerical values. If I draw the trace with the replace
, when the parseInt
enters action there should only be numbers in place to be converted, since the mask only allows the user to type numbers.
What am I doing wrong?