How to validate URL in ReactJS? Last Updated : 15 Mar, 2022 Comments Improve Suggest changes Like Article Like Report URL (Uniform Resource Locator) is a reference/address to a resource on the Internet. For example, www.geeksforgeeks.com is a URL. The following example shows how to validate the user entered data and check whether it is valid or not using the npm module in the ReactJS application. Creating React Application And Installing Module: Step 1: Create a React application using the following command: npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command: cd foldernameStep 3: After creating the ReactJS application, Install the validator module using the following command: npm install validatorProject Structure: It will look like the following. Project StructureApp.js: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. JavaScript import React, { useState } from "react"; import validator from 'validator' const App = () => { const [errorMessage, setErrorMessage] = useState('') const validate = (value) => { if (validator.isURL(value)) { setErrorMessage('Is Valid URL') } else { setErrorMessage('Is Not Valid URL') } } return ( <div style={{ marginLeft: '200px', }}> <pre> <h2>Validating URL in ReactJS</h2> <span>Enter URL: </span><input type="text" onChange={(e) => validate(e.target.value)}></input> <br /> <span style={{ fontWeight: 'bold', color: 'red', }}>{errorMessage}</span> </pre> </div> ); } export default App Step to Run Application: Run the application using the following command from the root directory of the project: npm startOutput: The following will be the output if the user enters an invalid URL as shown below:The following will be the output if the user enters a valid URL as shown below: Comment More infoAdvertise with us Next Article How to validate URL in ReactJS? G gouravhammad Follow Improve Article Tags : JavaScript Web Technologies ReactJS Similar Reads How to Validate a Date in ReactJS? Validating input Date in react ensures the correct date input. The valid date input is commonly used in case of calculating days, getting DOB for user data, and other operations etc.Prerequisites:React JSNode JS and NPMApproachTo validate a date in React we will use the validator npm package. Take t 2 min read How to Validate an Email in ReactJS ? Validating email in React is an important step to authenticate user email. It ensures the properly formatted email input from the user. The following example shows how to validate the user entered email and checking whether it is valid or not using the npm module in React Application.ApproachTo vali 2 min read How to Validate Octal number in ReactJS? The Octal numeral system is the base-8 number system which uses the digits 0 to 7. It is also known as Oct for short. The following example shows how to validate the user entered data and check whether it is valid or not using the npm module in the ReactJS application. ApproachTo validate octal numb 2 min read How to validate Passport Number is ReactJS? Passport Number validation is an important step in order to authenticate the user's passport number. The following example shows how to validate the user's passport number using the npm module in ReactJS. Syntax: isPassportNumber(str, countryCode) Parameters: This function accepts two parameters a 2 min read JavaScript - Validate URL in JS We will explore different approaches to validating URLs in JavaScript. These approaches include using regular expressions (regex), the URL constructor, and various npm packages. let's see one by one.All valid URLs follow a particular pattern. They have three main parts, which are: ProtocolDomain nam 2 min read Like