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 <[log in to unmask]>
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) <
> [log in to unmask]> 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
> >
>
|