prestaowner20 Posted August 8, 2023 Share Posted August 8, 2023 Hi guys, Im trying to update my validation method of customer name and last name, so it wont accept . and / because of spams... I tried : in www/classes/Customer public static $definition = array( 'table' => 'customer', 'primary' => 'id_customer', 'fields' => array( 'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false), 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32), 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32), in www/classes/Validate public static function isCustomerName($name) { if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'),$name)) return false; if (preg_match(Tools::cleanNonUnicodeSupport('[a-z0-9][\.]'),$name)) return false; if (preg_match(Tools::cleanNonUnicodeSupport('[a-z0-9][\/]'),$name)) return false; return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'),$name); } But name with . and / is stil accepted, could you please advise why ? I also updated : www/js/validate.js function validate_isName(s) { var reg = /^[^0-9!<>,;?=+()@#"°{}_$%:]+$/; var regspam = /[a-z0-9][\.]/; var regspamdva = /[a-z0-9][\/]/; return reg.test(s) && !regspam.test(s) && !regspamdva.test(s); } But with no success. Could you please advise what am I doing wrong ? Link to comment Share on other sites More sharing options...
AddWeb Solution Posted August 8, 2023 Share Posted August 8, 2023 52 minutes ago, prestaowner20 said: Hi guys, Im trying to update my validation method of customer name and last name, so it wont accept . and / because of spams... I tried : in www/classes/Customer public static $definition = array( 'table' => 'customer', 'primary' => 'id_customer', 'fields' => array( 'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false), 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32), 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32), in www/classes/Validate public static function isCustomerName($name) { if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'),$name)) return false; if (preg_match(Tools::cleanNonUnicodeSupport('[a-z0-9][\.]'),$name)) return false; if (preg_match(Tools::cleanNonUnicodeSupport('[a-z0-9][\/]'),$name)) return false; return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'),$name); } But name with . and / is stil accepted, could you please advise why ? I also updated : www/js/validate.js function validate_isName(s) { var reg = /^[^0-9!<>,;?=+()@#"°{}_$%:]+$/; var regspam = /[a-z0-9][\.]/; var regspamdva = /[a-z0-9][\/]/; return reg.test(s) && !regspam.test(s) && !regspamdva.test(s); } But with no success. Could you please advise what am I doing wrong ? Hi, I see a couple of issues in your code that might be causing the problem 1. In the www/classes/Customer file, you're trying to use regular expressions to validate the customer names. However, the regular expressions you're using might not be correct. The expressions [a-z0-9][\.] and [a-z0-9][\/] are not constructed properly to match names containing a dot or a slash. To match a dot or a slash, you should use [\.] and [\/] respectively. 2. In the www/classes/Validate file, your regular expressions for checking dots and slashes are incorrect. They are missing the quantifier (* or +) to indicate that the character should occur zero or more times. Additionally, you should be using the pipe | to combine multiple regular expressions. Try this, in your www/classes/Validate file: public static function isCustomerName($name) { if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[a-z0-9\.]/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[a-z0-9\/]/ui'), $name)) { return false; } return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'), $name); } And in your www/js/validate.js file, you need to adjust the regular expressions as well: function validate_isName(s) { var reg = /^[^0-9!<>,;?=+()@#"°{}_$%:]+$/; var regspam = /[a-z0-9\.]/; var regspamdva = /[a-z0-9\/]/; return reg.test(s) && !regspam.test(s) && !regspamdva.test(s); } After making these changes, Don't forget to Clear the cache. Let me know If it works! Thanks you! 1 Link to comment Share on other sites More sharing options...
prestaowner20 Posted August 8, 2023 Author Share Posted August 8, 2023 35 minutes ago, AddWeb Solution said: Hi, I see a couple of issues in your code that might be causing the problem 1. In the www/classes/Customer file, you're trying to use regular expressions to validate the customer names. However, the regular expressions you're using might not be correct. The expressions [a-z0-9][\.] and [a-z0-9][\/] are not constructed properly to match names containing a dot or a slash. To match a dot or a slash, you should use [\.] and [\/] respectively. 2. In the www/classes/Validate file, your regular expressions for checking dots and slashes are incorrect. They are missing the quantifier (* or +) to indicate that the character should occur zero or more times. Additionally, you should be using the pipe | to combine multiple regular expressions. Try this, in your www/classes/Validate file: public static function isCustomerName($name) { if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[a-z0-9\.]/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[a-z0-9\/]/ui'), $name)) { return false; } return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'), $name); } And in your www/js/validate.js file, you need to adjust the regular expressions as well: function validate_isName(s) { var reg = /^[^0-9!<>,;?=+()@#"°{}_$%:]+$/; var regspam = /[a-z0-9\.]/; var regspamdva = /[a-z0-9\/]/; return reg.test(s) && !regspam.test(s) && !regspamdva.test(s); } After making these changes, Don't forget to Clear the cache. Let me know If it works! Thanks you! Thank you very much ! I updated the rules to only return false when name conatins . or / and it now works like a charm! No spam for me I hope : thank you you saved me! in validate js : function validate_isName(s) { var reg = /^[^0-9!<>,;?=+()@#"°{}_$%:]+$/; var regspam = /[\.]/; var regspamdva = /[\/]/; return reg.test(s) && !regspam.test(s) && !regspamdva.test(s); } in Validate.php public static function isCustomerName($name) { if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[\.]/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[\/]/ui'), $name)) { return false; } return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'), $name); } Link to comment Share on other sites More sharing options...
AddWeb Solution Posted August 8, 2023 Share Posted August 8, 2023 6 minutes ago, prestaowner20 said: Thank you very much ! I updated the rules to only return false when name conatins . or / and it now works like a charm! No spam for me I hope : thank you you saved me! in validate js : function validate_isName(s) { var reg = /^[^0-9!<>,;?=+()@#"°{}_$%:]+$/; var regspam = /[\.]/; var regspamdva = /[\/]/; return reg.test(s) && !regspam.test(s) && !regspamdva.test(s); } in Validate.php public static function isCustomerName($name) { if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[\.]/ui'), $name)) { return false; } if (preg_match(Tools::cleanNonUnicodeSupport('/[\/]/ui'), $name)) { return false; } return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u'), $name); } That's Amazing. Thanks for the update! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now