किसी विशिष्ट URL को वैलिडेट करने के लिए, रेगुलर एक्सप्रेशन का उपयोग करें।
उदाहरण
कोड इस प्रकार है:
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"));
उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js
यहां, मेरा फ़ाइल नाम demo259.js है।
आउटपुट
यह कंसोल पर निम्नलिखित आउटपुट देगा:
PS C:\Users\Amit\javascript-code> node demo259.js index java