0

I want to validate TAX , NAME, TELEPHONE NO . Those are should be alpha-numeric.So used this method but in here i want to know can i do this same by short method in simply way without using so many "AND" s.

  IF REGEXP_LIKE(i.TAX, '^[A-Za-z0-9]+$') AND REGEXP_LIKE(i.NAME, '^[A-Za-z0-9]+$') AND REGEXP_LIKE(VarTelephone , '^[A-Za-z0-9]+$') THEN

      INSERT INTO BIZZXE_V2_SCH.SUPPLIER_CONTACTS
      (CONTACT_ID, SUPPLIER_ID, ADDRESS, ZIP_CODE, COUNTRY_ID, CITY_ID, TELEPHONE, FAX, EMAIL, XMLCOL)
      VALUES(VarContactId ,VarId, k.ADDRESS, k.ZIP_CODE, k.COUNTRY_ID, k.CITY_ID, k.TELEPHONE, k.FAX, k.EMAIL, VarContactDetail);

     ELSE 
       -- Start Return RVAL Messages --
       RVAL.EX_CODE:=1;
       RVAL.MESSAGE:='Supplier Tax and Supplier Name should be apha-numeric that is numbers letters and symbols..!';
       -- End Return RVAL Messages --
     END IF;

1 Answer 1

4

Since they all need to match the same Regex pattern, to be alphanumeric, you can validate on the concatenation of these 3 values:

IF REGEXP_LIKE(i.TAX || i.NAME || VarTelephone , '^[A-Za-z0-9]+$')

However this does not behave exactly as your question condition, since if just one or two of the values is empty, it would be evaluated true in this case and not in the other.

A possible workaround for that and in the case that you need different regex, for telephone verifying just digits ()- and + for instance, would be something like this:

IF REGEXP_LIKE(i.TAX || ' ' || i.NAME || ' ' || VarTelephone , 
    '^[A-Za-z0-9]+ [A-Za-z0-9]+ [\d()\-+]+$')

For this case all you have to make sure is that your chosen separator, in my case the space will never appear in any of the input texts.

Sign up to request clarification or add additional context in comments.

2 Comments

Although this answers the question, I think it is a bad approach. The OP should check each value individually and return an error message specific to the columns with problems. I also find it curious that a telephone number would have letters, but not '+', '(', ')', and '-'.
The first answer had a case were it would not behave just like question, edited to address this situation and also if you need a different regex validation, please check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.