rJ7 rJ7 - 1 year ago 54
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...

Answer Source

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" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download