mercredi 2 juillet 2014

Regular Expression to validate empty anchor with href and not empty anchor with name


Vote count:

0




Earlier I was using following RegExp for validating anchor with HREF attribute should have text in it:



//regex for invalid anchor tag like: <a href="#"/> or <a href="#"> </a>
var pattern = new RegExp('<a [^>]*(/>|>\\s*</a>)', 'g');


Now I have additional validation requirement that it should show valid if anchor with name attribute has no text as shown in folowing example:



<a href="www.google.com">the link</a> Valid
<a href="www.google.com"></a> Invalid
<a name="google">the link</a> Invalid
<a name="google"></a> Valid


Thank you, Greetings.



asked 3 mins ago






Aucun commentaire:

Enregistrer un commentaire