This evening I was looking for a way to validate an Umbraco node that could be either text or a numeric value, in my case a salary that could be either an hourly amount, an annual figure or a comment.
In the case where the node contained a value I wanted the XSLT to output a pound sign (£) and for any that contained text it would just output the text, as this could be something like "Contact Us" or "Negotiable"
I thought someone else might find this useful so here is the XSLT and the regular expression.
First if you are using Umbraco, don't forget to include the reference to the EXSLT Regular expression library at the top of your XSLT.
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltRegularExpressions">
Then the code I used was:
<xsl:if test="Exslt.ExsltRegularExpressions:match($currentPage/data [@alias='Salary'],
'^[0-9]*\,?[0-9]*\.?[0-9]+$') != ''">
This regular expression allows any number of digits, an optional comma, more digits, an optional decimal point and finally more digits, so all the following are valid: