rJ7 rJ7 - 7 months ago 32
HTML Question

How to get a particular word from the sentence?

I have input value like below:

<input type="text" value: "Part: PT001 Invoice: 1234" />

what I need is I want to get the part number alone "PT001" from the value of the input..

Note: PT001 is dynamically getting value...

Appreciate your thoughts...


Use String#match method with regex /\bPart:\s?(\S+)/ and get the capturing group value.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="Part: PT001 Invoice: 1234" />