Tuesday 17 October 2017

javascript - How to check an entire string if it contains a specific word using jQuery?

I need help on checking a certain word if it contains in a
string that is being assigned into my input textbox.
For example below, If
there's a string value assigned to this
textbox



            id="StartLocation" name="StartLocation" value="1 AAC, MT SECTION, RAF SCAMPTON, LINCOLN,
LN1 2ST, UNITED KINGDOM"
>



I want
to check if it contains the word "UNITED KINGDOM" and if
does not, it should return false.
I tried something like this below but it
keeps returning true because the alert message is always 'It contains United Kingdom'
even though I already
change the value.



if
($("input#StartLocation:contains('UNITED KINGDOM')")) {
alert('It contains
United Kingdom');
} else {
alert('It does not contains United
Kingdom');
}



How
do I fix this? Thanks...

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...