variable doesn't contain a number

Posted on 2012-08-30
Last Modified: 2012-09-25

I would like to do a check to see if a ID contains a number - this can feature anywhere in the ID...
<xsl:when test="not(contains($ID, '1234567890'))">

This doesn't seem to be working.

Also, I may want to add a second condition like

<xsl:when test="$productName='test' and not(contains($ID, '1234567890'))">

Can anyone assist?

Question by:Al4ddin2
    LVL 60

    Expert Comment

    by:Geert Bormans
    contains() works on a string, not per character
    you can translate the numbers away and see if it still equal

    test="translate($ID, '1234567890', '') = $ID"

    this test will be true when there are no numbers in $ID
    LVL 60

    Expert Comment

    by:Geert Bormans
    your compound test would be

    <xsl:when test="$productName='test' and translate($ID, '1234567890', '') = $ID">

    Author Comment

    Thanks Gertone,

    What about if it contains special characters i.e. &() etc.

    LVL 60

    Accepted Solution

    Here is how translate works

    translate($ID, '1234567890', '')

    replaces every occurence of a character in the second argument as found in the first argument with the character found in the same location in the third argument

    translate($ID, 'ab', 'AB')
    replaces every 'a' in $ID with a 'A' and every 'b' in $ID with a 'B'

    if there is nothing in the third argument, the character will be dropped

    translate($ID, 'ab', 'A')
    replaces every 'a' in $ID with 'A' and drops every 'b'

    translate($ID, '1234567890', '')
    drops every number in $ID
    if this returns something that is still the same as the original $ID, you know there weren't any numbers

    if you add more characters, the test will be stricter

    translate($ID, '1234567890&amp;()', '')
    is what you need
    (note that the parser will make the &amp; an &

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now