Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:37:55+00:00 2026-06-01T22:37:55+00:00

hello i am using javascript to validate field i am checking special characters.. the

  • 0

hello i am using javascript to validate field

i am checking special characters.. the code i am implementing validates all the special characters except _ underscore..

   <script type="text/javascript" language="javascript">
function validateForm()
{
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?_";

   for (var i = 0; i < document.reg_form.txtusername.value.length; i++) 
        {
            if (iChars.indexOf(document.reg_form.txtusername.value.charAt(i)) != -1) 
                {
                    alert ("Special Characters are not allowed.");
                    return false;
                        }
         }
    return true;
}
</script>

for this filed

<input name="txtusername" type="text" id="txtusername" maxlength="10" style="background-color:#CCC"  />

but its not validating the underscore

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:37:57+00:00Added an answer on June 1, 2026 at 10:37 pm

    characters in strings can be addressed as if the string were an array (which, if you think about it, it is). Since you’re looping through the string char-per-char, again, as you would with an array, why not be consistent in your logic?

    if (iChars.indexOf(document.reg_form.firstname.value[i]) !== -1)
    {
        alert('Foobar');
        return false;
    }
    

    That should work… Also: there’s no real need to escape the single quote, since the iChar string is delimited by double quotes… if all else fails, you might want to try omitting that backslash, too. Though I don’t think that’s what’s causing the problem

    It is working: here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello All I am using Javascript to calculate some values of textboxes .The calculations
Hi I want to search about some characters (or word) in text using JavaScript
I am try using prototype javascript framework. i have next code CheckBoxSlider = Class.create({
I'm using javascript (and jQuery) to move between three box descriptions. Javascript <script type=text/javascript>
Possible Duplicate: Count bytes in textarea using javascript Hello everyone. I am trying to
hello i am using httpUnit and i have the following error org.mozilla.javascript.EcmaError: TypeError: Cannot
I am using the following code to create a text file using javascript and
I have some troubles when using javascript code for Facebook invite friends. Details: User
how to split <p><span>Hello</span></p> to <span>Hello</span> using javascript var text = <p><span>Hello</span></p>; remember:I don't
I have a class: class MyClass(object): @property def myproperty(self): return 'hello' Using mox and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.