• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 67
  • Last Modified:

checking input of textbox

This is a follow up to this ticket.

https://www.experts-exchange.com/questions/29097874/using-jquery-or-JavaScript-to-prevent-user-from-typing-a-character-string-in-a-textbox.html?anchor=a42554070¬ificationFollowed=207158836#a42554070

This is just for learning purposes, learning to work with regex.

So in the example in that ticket, how would I revise it to the following.
Either using regex or jquery or JavaScript.

Add a button called Button1.

If I type the less than sign proceded by the forwad slash sign like this </ then hide the button.
If I type the greater than sign preceded by the forwad slash sign like this /> then hide the button.
0
maqskywalker
Asked:
maqskywalker
  • 3
1 Solution
 
Julian HansenCommented:
Is the button disabled if there is any /> or </ in the text
OR
Is the button disabled only at the point that you type the > in '/>'' or the '/' in '/>'
0
 
Julian HansenCommented:
Here is a sample that works on the contains approach
HTML
<textarea class="form-control" id="tester"></textarea>
<button class="btn btn-primary" id="thebutton">Click me</button>

Open in new window

JQuery
<script>
$(function() {
  $('#tester').keyup(function() {
    var disabled = $(this).val().indexOf('/>') > 0 || $(this).val().indexOf('</') > 0;
    $('#thebutton').prop({disabled: disabled});
  });
});
</script>

Open in new window

Working sample here
1
 
maqskywalkerAuthor Commented:
Thanks! Great example!
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now