I have a form that can give information on a domain name (not subdomains) and on IP addresses.
When the user enters the domain name or IP address into the appropriate form input box, I validate it to see if it is of the correct format.
For domain name I use:
For IP Address I use (IPV4):
They both work properly if the user enters the information directly into the form with their keyboard. However, if the user copies the domain or IP address and happens to copy a white space before and after the information, and pastes it into the input box, the form displays a format error. If I remove the beginning and ending space it works fine.
How can you ignore the beginning and ending white spaces so that the format becomes valid?