- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:34 AM
In a catalog item, it has two fields enter password and re-enter password, a logic should be built to validate if both passwords are same.
My Approach:
Used a Masked field type for both and tried running an onChange client script but seems something's wrong.
Code for client script:
var password = g_form.getValue('new_psk');
var pass = g_form.decrypt('new_psk');
// Your validation logic here
var regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+])[A-Za-z\d!@#$%^&*()_+]+$/;
if (!regex.test) {
alert('Password must be within double quotes and contain at least 1 uppercase, 1 lowercase, 1 number, and 1 special character.');
return false; // Prevent form submission
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 09:41 AM
Hello @sreeshsurendran ,
In that condition can you please change the logic from onChange to onSubmit and also please test using below code and let me know your views on this.
function onSubmit() {
var password = g_form.getValue('new_psk');
var confirmPassword = g_form.getValue('confirm_psk');
// Your validation logic here
var regex = /^\["(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+])[A-Za-z\d!@#$%^&*()_+]+"\]$/;
if (!regex.test(password)) {
alert('Password must be enclosed within square brackets [" "] and contain at least 1 uppercase, 1 lowercase, 1 number, and 1 special character.');
g_form.setValue('new_psk', ''); // Clear the password field
g_form.setValue('confirm_psk', ''); // Clear the confirm password field
return false; // Prevent form submission
}
// Check if the passwords match
if (password !== confirmPassword) {
alert('Passwords do not match.');
g_form.setValue('new_psk', ''); // Clear the password field
g_form.setValue('confirm_psk', ''); // Clear the confirm password field
return false; // Prevent form submission
}
// Continue with form submission or any other logic as needed
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:44 AM
Hello @sreeshsurendran
Can you test with the below code and let me know how that works for you.
var password = g_form.getValue('new_psk');
var confirmPassword = g_form.getValue('confirm_psk');
// Your validation logic here
var regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+])[A-Za-z\d!@#$%^&*()_+]+$/;
if (!regex.test(password)) {
alert('Password must contain at least 1 uppercase, 1 lowercase, 1 number, and 1 special character.');
g_form.setValue('new_psk', ''); // Clear the password field
g_form.setValue('confirm_psk', ''); // Clear the confirm password field
return false; // Prevent form submission
}
// Check if the passwords match
if (password !== confirmPassword) {
alert('Passwords do not match.');
g_form.setValue('new_psk', ''); // Clear the password field
g_form.setValue('confirm_psk', ''); // Clear the confirm password field
return false; // Prevent form submission
}
// Continue with form submission or any other logic as needed
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:57 AM
Hi @Aniket Chavan ,
I tried this logic, but one problem which I faced was, it was validating even before I enter the new password. Please check this and let me know.
Also, the business requirement is the password should be entered between [" "].
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 09:41 AM
Hello @sreeshsurendran ,
In that condition can you please change the logic from onChange to onSubmit and also please test using below code and let me know your views on this.
function onSubmit() {
var password = g_form.getValue('new_psk');
var confirmPassword = g_form.getValue('confirm_psk');
// Your validation logic here
var regex = /^\["(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+])[A-Za-z\d!@#$%^&*()_+]+"\]$/;
if (!regex.test(password)) {
alert('Password must be enclosed within square brackets [" "] and contain at least 1 uppercase, 1 lowercase, 1 number, and 1 special character.');
g_form.setValue('new_psk', ''); // Clear the password field
g_form.setValue('confirm_psk', ''); // Clear the confirm password field
return false; // Prevent form submission
}
// Check if the passwords match
if (password !== confirmPassword) {
alert('Passwords do not match.');
g_form.setValue('new_psk', ''); // Clear the password field
g_form.setValue('confirm_psk', ''); // Clear the confirm password field
return false; // Prevent form submission
}
// Continue with form submission or any other logic as needed
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 09:29 PM