Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try using match() and regex

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

https://regex101.com/r/F8VnaZ/1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading