samedi 3 janvier 2015

PHP Pattern to validate URL in English and persian(Farsi)

I have a pattern that checks the given url is correct or not and this is working perfectly fine in English, but when I give it Farsi characters it returns false because of invalid URL.


The code work with some URLs with mixed Farsi characters but it does not work with others! Where can I make a change or what I can add in this pattern so that it can also validate Farsi characters with English?



// check if URL is valid format
$pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w]([-\d\w]{0,253}[\d\w])?\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.,\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.,\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.,\/\d\w]|%[a-fA-f\d]{2,2})*)?$/';
$isLink = preg_match($pattern, $url); // Returns true if a link

Aucun commentaire:

Enregistrer un commentaire