Re: [CODE4LIB] javascript help (UNCLASSIFIED)

2018-01-18 Thread Jason Bengtson
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/ *

On Thu, Jan 18, 2018 at 10:51 AM, Mark Pernotto 
wrote:

> Without any more information, you could do something along these lines:
>
> var string  = '9-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@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
> >
>


Re: [CODE4LIB] javascript help (UNCLASSIFIED)

2018-01-18 Thread Craig Dietrich
There's a number of solutions:

https://goo.gl/KcSFTq

Personally. I'd use the jQuery function.

I'm much more interested in what "CLASSIFICATION: UNCLASSIFIED" means, is
that appended and prepended to every .mil email?

On Thu, Jan 18, 2018 at 8:51 AM, Mark Pernotto 
wrote:

> Without any more information, you could do something along these lines:
>
> var string  = '9-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@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
> >
>


Re: [CODE4LIB] javascript help (UNCLASSIFIED)

2018-01-18 Thread Bartikowski, Waldemar
Hi Kelly,


use Regular Expressions 
.
 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  on behalf of Zhu, Kaile NAF 
USARMY IMCOM HQ (US) 
Sent: Thursday, January 18, 2018 10:47
To: CODE4LIB@LISTS.CLIR.ORG
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


Re: [CODE4LIB] javascript help (UNCLASSIFIED)

2018-01-18 Thread Mark Pernotto
Without any more information, you could do something along these lines:

var string  = '9-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@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
>