Define Value range in element using startsWith() – jQuery


I need to know if there is a shorter way to simplify below line of code indicating possible values of an element that starts with a defined 3 digit numbers.

$('#nf-field-168').val().startsWith("010" | "011" | "012" | "013" | "014" | "015");

if there’s a way to define them as range (ex. 010 – 015) rather than using the vertical bar Operator? Is such method exist?

>Solution :

Try using match() and regex

$('#nf-field-168').val().match(/^01[0-5]/) // returns null if not matched

Leave a Reply Cancel reply