Remember that, as Java Script isn't available in all browsers, you should also use server-side scripting to validate all data before recording it in a database or elsewhere.
If the purpose of registration is to confirm that the person exists, and that they have supplied a valid email address, then as part of the registration processe you a should either email them a random password or a confirmation token rather than letting them choose their own password and use it immediately.
The code presented below would then be used for letting the user change their password.
This PHP login form using My SQL database connections contains PHP 7.0 methods only.
Many methods like mysql_real_escape_string(), mysql_query(), mysql_num_rows(), mysql_connect(), mysql_select_db(), mysql_close() were deprecated in PHP 5 and removed from the latest version of PHP i.e. It uses prepared statements and My SQL scripts to create a PHP login page with validations" data-medium-file="https://i0com/krazytech.com/wp-content/uploads/2017/03/My SQL-scripts-to-create-a-PHP-login-page-with-validations.jpg?
Another method is to display what they've entered as part of a 'confirmation page'.