How to validate URL in ReactJS? Last Updated : 15 Mar, 2022 Summarize Comments Improve Suggest changes Share 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 apply validation on Props in ReactJS ? G gouravhammad Follow Improve Article Tags : 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 How to apply validation on Props in ReactJS ? Need of Validating Props in React JS Props are used to pass the read-only attributes to React components. For the proper functioning of components and to avoid future bugs and glitches it is necessary that props are passed correctly. Hence, it is required to use props validation to improve the react 3 min read How to validate mobile number length in ReactJS ? Validating mobile number length in React JS App is an important step to check whether the number entered by the user is genuine or not. It is effective in many case like creating a user form, collection of employee details, etc.Approaches to validate mobile number length in React Js areTable of Cont 3 min read Like