I have a database of a few hundred schools (more added constantly) where one field has a verbose description of the grade levels it serves. Examples: 'K-6', '9-12', 'PK-4', 'K-3 and 6-8', 'grades 4-8'
I am rendering this data in an HTML table and using a 'select' drop-down to filter by specific grade. I would like to have the 'options' for this drop-down be single grades, such as K, 1st, 2nd, 3rd, etc. But I need a regex or some means (via javascript) to compare to this field to be sure the user-selected grade falls within the range so I can highlight the 'tab开发者_如何转开发le' row.
BTW, I am also using the jquery library.
Try this to search the description for ranges:
/(PK|[K1-9])(\s*(-|to)\s*)(PK|[K1-9])/i
Test it.
Of course you may want to modify it and add some extra logic. It's just a starting point.
I hope this helps you,
Alin
精彩评论