Re: Check for special character

From: Alexis Huxley (ahuxley_at_gmx.net)
Date: 10/28/04


Date: Thu, 28 Oct 2004 09:49:05 +0200


> My script accept user input into a variable USRIP.
> I only want input to have (aA-zZ or 0-9).
> How do I check that the variable USRIP doesn't has special character (e.g
> #$* @ etc etc) and only has aA-zZ and 0-9?

How about:

        if ! expr "$USRIP" : '[a-zA-Z0-9]*$' > /dev/null; then
                echo "bad input"
                return 1 # or exit or whatever
        fi

Repeat the square-bracketed term to specify at least one
occurence of one of those chars if empty input is not
acceptable.

Alexis
            



Relevant Pages

  • Check for special character
    ... My script accept user input into a variable USRIP. ... I only want input to have (aA-zZ or 0-9). ...
    (comp.unix.shell)
  • Re: Check for special character
    ... > My script accept user input into a variable USRIP. ... > How do I check that the variable USRIP doesn't has special character (e.g ...
    (comp.unix.shell)
  • Re: Check for special character
    ... >> My script accept user input into a variable USRIP. ... print "contains only desired chars" ...
    (comp.unix.shell)
  • Re: Check for special character
    ... > My script accept user input into a variable USRIP. ... > How do I check that the variable USRIP doesn't has special character (e.g ...
    (comp.unix.shell)
  • Loop Through UserForm For Multiple Different Outputs
    ... I have a UserForm that I want to repeat so I can get different user input. ... Does anyone know of a way to pause the code while the UserForm is being ...
    (microsoft.public.excel.programming)