how to check user data

RAVI 896 Reputation points
2024-04-16T12:33:55.6866667+00:00

Hello

In asp.net textbox if user enter something like this with special charater i need to show alert check data

For example

  1. APPLE /45 it has auto correct like this APPLE /45
  2. MFLOW +/ CURRENT it has to auto corrrect like this MFLOW / CURRENT
  3. HELLO 'C' it has to correct to HELLO

how to solve this type of error using C# or javascript onekypress

Thanking You

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,265 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,636 Reputation points Microsoft Vendor
    2024-04-17T03:48:08.02+00:00

    Hi @RAVI,

    The onkeypress event is deprecated.You can use onchange Event.

    APPLE /45 it has auto correct like this APPLE /45

    Didn't see anything that needed to be changed.

    MFLOW +/ CURRENT it has to auto corrrect like this MFLOW / CURRENT

    Remove the plus sign:\\+

    HELLO 'C' it has to correct to HELLO

    Do you want to remove the quotes and everything in them?If so, you can use '\\w+\\'

    All code

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>     
        <script>
            function myFunction() {
                var Regex = new RegExp("'\\w+\\'|\\+");
                var word = document.getElementById("TextBox1").value;
                console.log(word);
                var istr = Regex.test(word);
                if (istr) {
                    alert("Unnecessary Characters! Corrected!")              
                    var a = word.replace(Regex, '');
                    document.getElementById("TextBox1").value = a;
                }                      
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server" onchange="myFunction()"></asp:TextBox>
            </div>
        </form>
    </body>
    </html>
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments