Click here to Skip to main content
12,406,124 members (75,928 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP jQuery
Hi,
I need to remove special characters in the first character of the string. How to do this?
Posted 17-Apr-13 0:31am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

hi,

var string = "I'm a very^ we!rd* Str!ng.";
$('body').html(string.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-'));

Once go through below link..

How to remove special character from a string with the help of jquery or javascript[^]
  Permalink  
v2
Comments
Member 9762654 17-Apr-13 6:52am
   
this will remove all the special character i need to remove only from the first place of string for example if my string is !he#llo after removing it should be he#llo
Member61 17-Apr-13 6:58am
   
If u have all these in database u can do it very easy..
Member61 17-Apr-13 6:58am
   
Through query..
Member 9762654 17-Apr-13 7:00am
   
no i jus want to validate whenever user enters in textbox
Member61 17-Apr-13 7:12am
   
Then u have to write a javascript code, that accepts a first char special symbol and then all other chars alphabets... right?
Member 9762654 17-Apr-13 7:26am
   
thats wat i m searching i couldn't get anywhere
Member61 17-Apr-13 7:56am
   
Check my solution below...
and let me know whether it helped u or not?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

hi,
plz go through the below code, this solution is very to ur problem. now next thing what u have to do is split the variable x into array and then check the array variable's first char whether it is a symbol or alphabet. below this code im giving one more link for splitting this variable to array. plz go through that link also.


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
 
        function tSpeedValue() {
            debugger;
            var x = document.getElementById("TextBox1").value;
 
            alert(x);
 

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input ID="TextBox1"  onblur="tSpeedValue(this)"></input>
    </div>
    </form>
</body>
</html>


http://roseindia.net/java/javascript-array/javascript-array-string.shtml[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I have solved this
$(document).ready(function(){
$("#txt1").blur(function() {
		 var x=$("#txt1").val();
		 var s=x.substring(0,1);
		 var d=s.match(/[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/);
		 
		if(d!=null)
		{	
			$("#msg").html('<font color="red">Invalid Company name</font>');
			}
			else if(x=="")
			{
				
				$("#msg").html('');
				}
				
});  
$("#txt1").keyup(function() {
		 var x=$("#txt1").val();
		 if(x=="")
			{
				
				$("#msg").html('');
				}
				
});  
    });

where msg is my label
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160726.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100