开发者

How do i ensure that my textarea value should always contain the word "india" in javascript?

开发者 https://www.devze.com 2023-01-16 12:25 出处:网络
How do i ensure that my textarea value should开发者_开发知识库 always contain the word \"india\" in javascript?

How do i ensure that my textarea value should开发者_开发知识库 always contain the word "india" in javascript?

Actually i want to validate the textarea so that the user should always the word "india" in that.

Please help me. Thanks in advance.


You can use the blur event which is invoked when the user removes focus from the textarea.

<textarea onblur="return validate(this);"></textarea>

var reg = /\bindia\b/im;
function validate(textArea) {
    // case-insensitive search for "india"
    if (!reg.test(textArea.value)) {
        alert("Where's India?");
    }
}


<textarea onchange='if(this.value.indexOf("india") == -1) this.value = "";'></textarea>
0

精彩评论

暂无评论...
验证码 换一张
取 消