Re: javascript help (UNCLASSIFIED)

From: Jason Bengtson <j.bengtsonunm_at_nyob>
Date: Thu, 18 Jan 2018 10:58:00 -0600
To: CODE4LIB_at_LISTS.CLIR.ORG
Use regex to check the substring. Set your regex value (var testo =
/^[-+]?[0-9]+$/;) and use the match method or similar to test the result (
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
)

Best regards,

*Jason Bengtson*


*http://www.jasonbengtson.com/ <http://www.jasonbengtson.com/>*

On Thu, Jan 18, 2018 at 10:51 AM, Mark Pernotto <mark.pernotto_at_gmail.com>
wrote:

> Without any more information, you could do something along these lines:
>
> var string  = '99999-0123';
> var newstring = string.slice(0,-5);
>
> But that won't take into account if the first 5 numbers are, in fact,
> numeric.  Should the numeric check occur prior to the string slicing?
>
> Mark
>
>
> On Thu, Jan 18, 2018 at 8:47 AM, Zhu, Kaile NAF USARMY IMCOM HQ (US) <
> kaile.zhu.naf_at_mail.mil> wrote:
>
> > 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
> >
>
Received on Thu Jan 18 2018 - 11:59:04 EST