Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Validation for a Currency textbox

Validation for a Currency textbox

Scheduled Pinned Locked Moved ASP.NET
sysadminhelptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MichaeltCheong
    wrote on last edited by
    #1

    Who can help me on expression i want the format must be 20.00 must .00 at the back , what i should add in with my expression?

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
    ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
    ValidationExpression="^\s*\$?\s*\d{1,3}((,\d{3})*|\d*)(\.\d{2})?\s*$">*</asp:RegularExpressionValidator>

    this expression only can check first digit cant be . only allow digit, and cant check after . must be 2digit at the back for example 20.00

    A Y 2 Replies Last reply
    0
    • M MichaeltCheong

      Who can help me on expression i want the format must be 20.00 must .00 at the back , what i should add in with my expression?

      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
      ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
      ValidationExpression="^\s*\$?\s*\d{1,3}((,\d{3})*|\d*)(\.\d{2})?\s*$">*</asp:RegularExpressionValidator>

      this expression only can check first digit cant be . only allow digit, and cant check after . must be 2digit at the back for example 20.00

      A Offline
      A Offline
      AmitGajjar
      wrote on last edited by
      #2

      Hi, I am not sure about the Regular expression but have couple of other solutions. 1) if you need to store decimal point in the database then that can be done through c# code as well.

      decimal.Round(yourValue, 2, MidpointRounding.AwayFromZero);

      1. Another way is to create javascript on the lost focus of your textbox. in the javascript function you can check for the decimal point if it is not exist then you can append that in the text box. Hope this information may lead you to some work around. Best luck

      Thanks -Amit Gajjar (MinterProject)

      1 Reply Last reply
      0
      • M MichaeltCheong

        Who can help me on expression i want the format must be 20.00 must .00 at the back , what i should add in with my expression?

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
        ValidationExpression="^\s*\$?\s*\d{1,3}((,\d{3})*|\d*)(\.\d{2})?\s*$">*</asp:RegularExpressionValidator>

        this expression only can check first digit cant be . only allow digit, and cant check after . must be 2digit at the back for example 20.00

        Y Offline
        Y Offline
        Yosh_
        wrote on last edited by
        #3

        Try it this way:

            \*
        

        He who goes for revenge must first dig two graves.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups