[英]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 我试图做类似的事情(js),但这可能是某人做过的最错误的方式
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');
}
}
You could check if input field contains only letters that way: 您可以通过以下方式检查输入字段是否仅包含字母:
var letters = /^[a-z]+$/;
if( namep.value.match(letters) ) {
// string contains only letters.
}
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.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.