diff --git a/src/utils/identifyInput.js b/src/utils/identifyInput.js index 3bd8826..98c6a85 100644 --- a/src/utils/identifyInput.js +++ b/src/utils/identifyInput.js @@ -9,11 +9,17 @@ const identifyInput = (input) => { * 网址正则 * @type {RegExp} */ - const urlRegex = - /^(?:(?:(?:https?|ftp):)?\/\/)?(?:\d{1,3}(?:\.\d{1,3}){3}|[a-z0-9-]+\.[a-z]{2,})(?::\d+)?(?:\/[^?\s]*)?$/i; - - const ipv4Regex = - /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; + const urlRegex = new RegExp( + "^(http://www.|https://www.|http://|https://)?[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$", + ); + + /** + * IP 正则 + * @type {RegExp} + */ + const ipv4Regex = new RegExp( + "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", + ); /** * 邮箱正则