Reputation: 3678
im trying to replace text in a text on blur so if the user enters this:
Hello/test
i want it to be replaced by:
test
im using a basic textbox:
<asp:TextBox runat="server" ID="fullName" CssClass="textBoxes"></asp:TextBox>
with asp.net 4.0 and jquery.
how can i do that?
thanks.
Upvotes: 1
Views: 633
Reputation: 337560
Assuming the functionality you want it to only keep the value of the string after the /
, not just to simply replace the 'Hello/', try this:
$(".textBoxes").blur(function() {
var values = $(this).val().split('/');
$(this).val(values[values.length-1])
});
Upvotes: 1
Reputation: 76003
You can use RegExp to replace the unwanted string(s) with a blank string:
$('textarea, input[type="text"]').on('blur', function () {
this.value = this.value.replace(/(hello\/)/gi, '');
});
This regular expression looks for any instance of hello/
(case-insensitive) and replaces it with a empty string.
Here is a demo: http://jsfiddle.net/K8xMf/
Upvotes: 0