How to remove php tag using javascript regular expression?

Posted: May 8, 2013 in Magento, Version 1.3.*, Version 1.4.*, Version 1.6.*

Hello Everyone,

 

After a long search i found solution to validate php tags using javascript from input values in magento.

 

I have modified magento/js/prototype/validation.js file and added new class to validate php tags:

You can review below code inside ‘Validation.addAllThese’ array  to add new class to validate php tags.


['validate-no-php-tags', 'PHP tags are not allowed', function(v) {

return  !/<\?[=|?php]?[\s\S]*?\?>/.test(v) && !/<\?[=|php]?[\s\S]*?/.test(v) && !/\?[\s\S]*?/.test(v) ;

}],

you can use ‘validate-no-php-tags’  css class in input tag in magento.

Above validation will validate tags like ‘<?php’, ‘<?’, ‘?>’, ‘<?php ?>’, ‘<? ?>’.

I hope above solution works like  charm.

 

Thanks,

Bijal Bhavsar

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.