Regular expression for validating names and surnames
Additional logic is required to prevent something like passing as a valid domain name or to confirm that the domain is actually hosted somewhere—but I’ll leave that as an exercise for the reader.I’ve had to retort to a very simple regex which just checks for an @ sign, something before it, at least one dot after it and at least 2 letters in the last suffix.So here is the Regular expression pattern:/^[A-Z][0-9] ?[0-9][A-Z]$/i The i at the end of the pattern is to indicate that this is a case insensitive match.Now let’s jump into the fun part which is discussing the regular expression First we have the starting and ending slashes “/” , the expression then starts with a “^” sign to match with the beginning of the string.Notice the [-\s\.] this part matches a hyphen(-) space or a dot (.).[0-9] means 3 digits.Single character domains are allowed (did you know Pay Pal owns x.com?
But once installed, Mint will run on a site served from an IP address.
So using the list of generic and country-specific top level domains (combined list) provided by the Internet Assigned Numbers Authority I put this together: /^([a-z0-9]([-a-z0-9]*[a-z0-9])?
\.) ((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i It checks against all known tlds and ensures that the domain name begins and ends with an alphanumeric character, allowing for dashes and sub-domains.
In this tutorial you will see how to use regular expressions to validate.
Through a list of examples , we will build a script to validate phone numbers , UK postal codes, along with more examples.