Validation for the password (No JS)

I have 2 password fields…Second field is to make sure that each match each other.
I am using regular expression for validation of the password in the first field (for simplicity pattern=“[a-zA-Z]”.

How would I validate second password input to match the first one in order to receive valid or invalid state?


I don’t think that’s possible without Javascript. Also, doing password validations on client side is dangerous. Anyone can modify it. If for example, the HTML or Javascript element has an attribute like required, I can simply remove that with my Inspect Tools option. Then send data empty data or data that you don’t want to your database. So for instance, if you’re looking for only letters in your password. I can simply modify the HTML or Javascript, remove that requirement attribute and then pass numbers with letters into the text field.

You should be validating on the server-side instead.


Yes for sure. I am already doing that. Just wanted to see what I can do if JS is disabled

IMO, you don’t need to do any fancy validations on the client side at all. Doing validations on your server-side is more safer because they cannot modify the server-side codes.

1 Like

Yes, AFAIK the HTML “validate” only validates the inputs syntax to ensure it’s in the correct format.

This is a good thing for honest users because they will get immediate feedback if they make a mistake. For not so honest users, not so much.

Similarly, having some JavaScript layered on top of the HTML validate can be a good thing for honest users.

But when it comes down to ensuring validity for all users, that really needs to be done server-side.


Hey Stribor45

like everyone says client side security check is unsafe as it can be disabled or tampered with so to use validation using PHP is a good server side security besides judging from the password thing I’d assume you are using database, So PHP works well with MYSQL so definitely something to look into

In theory you would simply check that the code in input fields are filtered to check for empty fields, to remove any html tags or “/.,” etc than to validate the second form would be to link the first input field with the second maybe in a form of a single function or linking functions after one another but just like javascript applying a variable toone input can be done the same to the second input field than use a if function to determine “if a=B” that is simplest sorry for not having any code as I am not a programmer wiz but in theory thats how I would see It I do use PHP but been awhile since I used it so refreshing my memory could help lol.

1 Like

You can’t check the two values match on the client side without js, so you will have to rely on the server side to do it, which you should have already.
The built in browser validation only does simple things like required, min/max/ length, patterns, etc.
It won’t do things where different inputs depend upon each other, that needs scripting.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.