PHP and JavaScript Validation Check

Started by vinodkumar, Oct 14, 2022, 03:24 AM

Previous topic - Next topic

vinodkumarTopic starter

I am making an authorization registration form.
It is necessary to implement a qualitative validation check. There are no problems with JavaScript , the correctness of the filling is checked, but in order to check whether a user with such a login exists during registration, you need to call the PHP code, I do this through the submit button and the method of sending the POST form.
In this case, the check is normal, but the page goes to the execution directory of this php, that is, it is updated. And I need the PHP check to be similar to the JS check, and if the user already exists with such a login, output the error using JavaScript on the same page without updating it. I have not found suitable methods to solve this problem. Please help anyone who has encountered this.
  •  

microsoftcygnet

Sometimes the validation built into the browser is not enough. We may need the input data to satisfy some additional rules. For instance, to specify special characters in a text field.
Since we are already checking all possible errors manually in our CustomValidation.prototype.checkValidity function, we can simply add a few more checks there.

CustomValidation.prototype.checkValidity = function(input) {

  // Here are the built-in validity checks

  // And here are special
  if (!input.value.match(/[a-z]/g)) {
    this.addInvalidity('At least 1 lowercase letter is required');
  }

  if (!input.value.match(/[A-Z]/g)) {
    this.addInvalidity('At least 1 uppercase letter is required');
  }
};


Real-time validation
Although the current method looks much better, it is also not without flaws.
The worst of the shortcomings is that the user will not be able to see any messages until he clicks on the submit form button. It would be much better if the validation of the field occurred immediately when it was filled in. There are three rules to make it convenient to work with the form:

The requirements for each field are clearly visible before the user starts typing.
As soon as the user begins to enter data, observing the requirements, he immediately sees an indicator of successful completion of the field or hints if there are errors.
It is necessary to display error messages in such a way that the user cannot send an incorrectly filled form.
  •