Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear sir,


I need only number,


example: my input is (044)(2000023) and stored it in database.
and get only 0442000023.


How to write code


please tell me

by mohan
Posted

you can use regex for defining the control to allow the user to enter only the number and get number.. [0-9]...
 
Share this answer
 
You can use jQuery validation .......
 
Share this answer
 
I think you're asking: how to get only the numeric characters out of a string, ignoring everything else. You could use a regex and then stick all the matches together, but that seems like overkill when you can process it character by character easily enough:

string NumbersOnly(string input){
 StringBuilder output = new StringBuilder();
 foreach(char c in input)
  if(c >= '0' && c <= '9') output.Append(c);
 return output.ToString();
}
 
Share this answer
 
if your input is (123)(12345)
then you can use split properties of the string...
eg.
string num =(123)(12345);

now you can split it into two half..
string[] newnum = num.Split('(');

now you get newnum[0]=123)
and next is newnum[1]=12345)
again you can use for loop next to omit ')'
string fnum;
string snum;
for(int i = 0; i < newnum.Length; i++)
{
   if(i==0)
   {
      string[] num = newnum[i].Split(')');
      fnum = num[0];
      //here fnum = 123
   }
   
   else if(i==1)
   {
      string[] num = newnum[i].Split(')');
      snum = num[1];
      //here snum = 12345;
   }
}


Thus, you can use 'SPLIT' to split the string....
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900