<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Validate password in Catalog Item in Service Management forum</title>
    <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767658#M35464</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/472151"&gt;@sreeshsurendran&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Can you test with the below code and let me know how that works for you.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)(?=.*[!@#$%^&amp;amp;*()_+])[A-Za-z\d!@#$%^&amp;amp;*()_+]+$/;

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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Let me know your views on this and Mark &lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt;&lt;STRONG&gt;Correct if this solves your query and also mark &lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;STRONG&gt;Helpful if you find my response worthy based on the impact.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Aniket&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 15:44:20 GMT</pubDate>
    <dc:creator>AniketC85155510</dc:creator>
    <dc:date>2023-12-19T15:44:20Z</dc:date>
    <item>
      <title>Validate password in Catalog Item</title>
      <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767644#M35463</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Used a Masked field type for both and tried running an onChange client script but seems something's wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code for client script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)(?=.*[!@#$%^&amp;amp;*()_+])[A-Za-z\d!@#$%^&amp;amp;*()_+]+$/;
 
    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
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 Dec 2023 15:34:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767644#M35463</guid>
      <dc:creator>sreeshsurendran</dc:creator>
      <dc:date>2023-12-19T15:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Validate password in Catalog Item</title>
      <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767658#M35464</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/472151"&gt;@sreeshsurendran&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Can you test with the below code and let me know how that works for you.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)(?=.*[!@#$%^&amp;amp;*()_+])[A-Za-z\d!@#$%^&amp;amp;*()_+]+$/;

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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Let me know your views on this and Mark &lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt;&lt;STRONG&gt;Correct if this solves your query and also mark &lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;STRONG&gt;Helpful if you find my response worthy based on the impact.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Aniket&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 15:44:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767658#M35464</guid>
      <dc:creator>AniketC85155510</dc:creator>
      <dc:date>2023-12-19T15:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Validate password in Catalog Item</title>
      <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767677#M35467</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/133564"&gt;@AniketC85155510&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the business requirement is the password should be entered between [" "].&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 15:57:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767677#M35467</guid>
      <dc:creator>sreeshsurendran</dc:creator>
      <dc:date>2023-12-19T15:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Validate password in Catalog Item</title>
      <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767793#M35471</link>
      <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/472151"&gt;@sreeshsurendran&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)(?=.*[!@#$%^&amp;amp;*()_+])[A-Za-z\d!@#$%^&amp;amp;*()_+]+"\]$/;

    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;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 17:41:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2767793#M35471</guid>
      <dc:creator>AniketC85155510</dc:creator>
      <dc:date>2023-12-19T17:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Validate password in Catalog Item</title>
      <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2768259#M35473</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/133564"&gt;@AniketC85155510&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the solution. It's working as expected. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sreesh&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 05:29:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2768259#M35473</guid>
      <dc:creator>sreeshsurendran</dc:creator>
      <dc:date>2023-12-20T05:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Validate password in Catalog Item</title>
      <link>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2768280#M35474</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/472151"&gt;@sreeshsurendran&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Welcome and glad to hear that the solution worked for you and please mark my solution&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;Helpful.&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Aniket.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 05:40:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/service-management-forum/validate-password-in-catalog-item/m-p/2768280#M35474</guid>
      <dc:creator>AniketC85155510</dc:creator>
      <dc:date>2023-12-20T05:40:26Z</dc:date>
    </item>
  </channel>
</rss>

