
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Validate Tutorialspoint URL via JavaScript Regex
To validate a specific URL, use regular expression.
Example
The code is as follows −
function validateSoundURL(myURL) { var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/; return myURL.match(regularExpression) && myURL.match(regularExpression)[2] } console.log(validateSoundURL("https://tutorialspoint.com/index")); console.log(validateSoundURL("https://tutorialspoint.com/java"));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo259.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo259.js index java
Advertisements