code_junkie

Force ASP.NET textbox to display currency with $ sign

Nov 11th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // directive
  2. using System.Globalization;
  3.  
  4. // code
  5. decimal input = -1;
  6. if (decimal.TryParse(txtUserInput.Text, NumberStyles.Currency,
  7. CultureInfo.InvariantCulture, out input))
  8. {
  9. parameter = input.ToString();
  10. }
  11.  
  12. decimal sValue = decimal.Parse(txtboxValue.Text.Trim());
  13. // Put Code to check whether the $ sign already exist or not.
  14. //Try making a function returning boolean
  15. //if Dollar sign not available do this
  16. { string LableText = string.Format("{0:c}", sValue); }
  17. else
  18. { string LableText = Convert.ToString(sValue); }
  19.  
  20. string sValue = Convert.ToString(txtboxValue.Text.Trim());
  21. // Put Code to check whether the $ sign already exist or not.
  22. //Try making a function returning boolean
  23. //if Dollar sign not available do this
  24. { string LableText = string.Format("{0:c}", "sValue"); }
  25. else
  26. { string LableText = Convert.ToString(sValue); }
  27.  
  28. string value = text_box_to_validate.Text;
  29.  
  30. string myPattern = @"^$(d{1,3},?(d{3},?)*d{3}(.d{0,2})|d{1,3}(.d{2})|.d{2})$";
  31. Regex r = new Regex(myPattern);
  32. Match m = r.Match(value);
  33.  
  34. if (m.Success)
  35. {
  36. //do something -- everything passed
  37. }
  38. else
  39. {
  40. //did not match
  41. //could check if number is good, but is just missing $ in front
  42. }
Add Comment
Please, Sign In to add comment