Search code examples
javascriptcoffeescript

CoffeeScript checking to see if value entered is 4 or 5 digits long?


Right now this statement is checking to see if the number entered (sn_val) is 4 digits long:

if bin_model isnt "Accessories" and (sn_val.length isnt 4 or !$.isNumeric(sn_val))

Does anyone know how I could get it to allow numbers of either 4 or 5 digits in length? I've tried this (sn_val.length isnt 4 or 5 or !$.isNumeric(sn_val)) and this (sn_val.length isnt 4 or sn_val.length isnt 5 or !$.isNumeric(sn_val)) but neither of these seemed to work. I'm new to CoffeeScript so any help is appreciated.


Solution

  • Solved it by using this line instead:

    else if bin_model isnt "Accessories" and ((!sn_val.match(/^[0-9]{4,5}$/)) or !$.isNumeric(sn_val))

    https://forums.asp.net/t/1824542.aspx?+0+9+1+3+Regular+Expression+Interpret+Please is where I got the help from.