0

Im trying to implement a validation for an input field in IBM BPM. Im not really familiar with java script but I try to get method that returns ture if a string contains any numbers.

awdadw = valid
awdawd2d = invalid

I tried this method:

function hasNumbers(t)
{
    var pattern=new RegExp("^[A-Za-z]+$"); 
    return pattern.test(t); // true if string. Returns false for numbers
}

When I try this function, it says that method / variable RegExp is unknown. Since it is rather basci stuff I hope to get some sources where this topic is explained.

2

2 Answers 2

2

You can use this:

function validate(){    
var re = /^[A-Za-z]+$/;
if(re.test(document.getElementById("inputID").value))
   alert('Valid Name.');
else
   alert('Invalid Name.');      
  }
Sign up to request clarification or add additional context in comments.

2 Comments

worked for me thanks. but I modified it a bid for my needs
but this code then does not allow "-" which is necessary for some names. How can I build this function, to allow this?
0

Based on adre3wap this worked for me:

function validate(t){
  var re = /^[A-Za-z]+$/;
  if(re.test(t))
     return false;
  else
     return true;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.