Print

Print


Hi Kelly,


use Regular Expressions <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp>. This should be the easiest way to go:


---


var matching = "matching string 12345";
var not_matching = "not matching string 12a42";

// This checks if the last five characters are digits
var regex = /\d{5}$/;

alert( regex.test( matching ) );
alert( regex.test( not_matching ) );

---

Waldemar Bartikowski


________________________________
From: Code for Libraries <[log in to unmask]> on behalf of Zhu, Kaile NAF USARMY IMCOM HQ (US) <[log in to unmask]>
Sent: Thursday, January 18, 2018 10:47
To: [log in to unmask]
Subject: [CODE4LIB] javascript help (UNCLASSIFIED)

CLASSIFICATION: UNCLASSIFIED

Anybody can help me with such JavaScript code that can chop the ending portion of the string - last 5 characters - verifying if it is all numbers (zip code)?

Thanks.

Kelly Zhu

CLASSIFICATION: UNCLASSIFIED