1

hi i want to a one line of code (without using loop) in javascript to find the if there is semicolon in a string... please help if any one knows

2 Answers 2

10
myStringVal.indexOf(";") !== -1;

For more information, check out the documentation for String.prototype.indexOf().

Sign up to request clarification or add additional context in comments.

1 Comment

+1 (although I always advocate >= 0 rather than != -1 out of paranoia; but the spec does specifically say -1 for not found, so...) But please refer people to the specification. w3schools is incomplete at best.
2
if (stringvalue.indexOf(";") >= 0) {
    alert("String value contains semi colon");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.