omer malka
omer malka

Reputation: 154

How to Check if i have text in my input

I would like to make a small program that will check if I have any text inside the input field ... if its a number it's easy i just do

cardsp.value >= 1    

But when the input is text how can I check if there is anything in the field?

Name : <input id="namep" type="text" />

I tried to do something like that (js) but that probably the most wrong way that someone ever does

    var array= ["","a","b","c","d","e","f","g","h","i","j","k","m","n","l","o","p","q","r","s","t","u","v","w","x","y","z"];
function pay()  {
    namep.value 
    if(namep.value >= array.indexOf("a"), cardsp.value >= 1 , emailpa.value >= 1){

         alert('Ty For Buying a Ticket From our compeny , you will receive the Invoicing in the ' +emailpa.value);
        }

    else if(namep.value == array.indexOf(""){
            alert('Please Write Your Name');
    }

    }

Upvotes: 0

Views: 65

Answers (2)

KondukterCRO
KondukterCRO

Reputation: 543

 var input=$("#namep").val();

or

var input = document.getElementById('namep').value;

and then check if there is something...

if(input.length>0)
{
 //do something. 
}

or

var inputLength = input.length;

if(inputLength>0)
{
 //do something. 
}

Upvotes: 0

bpavlov
bpavlov

Reputation: 1090

You could check if input field contains only letters that way:

var letters = /^[a-z]+$/;  
if( namep.value.match(letters) ) {
  // string contains only letters.
}

Upvotes: 1

Related Questions