
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if a string has a certain piece of text in JavaScript?
The jQuery search() method is used to check whether a string contains a certain text in JavaScript.
You can try to run the following code to check whether “Tutorialspoint: Free Video Tutorials” contains the “Free Video” text in JavaScript or not:
<html> <head> <title>JavaScript String search() Method</title> </head> <body> <script> var re = "Free Video"; var str = "Tutorialspoint: Free Video Tutorials"; if ( str.search(re) == -1 ) { document.write("Does not contain" ); } else { document.write("Contains" ); } </script> </body> </html>
- Related Questions & Answers
- Check if a string has white space in JavaScript?
- How to check if a string contains a certain word in C#?
- How to check if an element has a certain class name with jQuery?
- MySQL query to check if a certain row has only two words?
- How to check if a string only contains certain characters in Python?
- How can tf.text be used to see if a string has a certain property in Python?
- PHP program to check if a string has a special character
- C++ Program to check if a string has been seen before
- How to check if a date has passed in MySQL?
- How do I check if a string has alphabets or numbers in Python?
- Check if a string has m consecutive 1s or 0s in Python
- Check if a binary string has two consecutive occurrences of one everywhere in C++
- How to check if an element has a class in jQuery?
- How to test if a JavaScript cookie has expired?
- Check if a string is sorted in JavaScript
Advertisements