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

  • SEARCH
  • Home
  • 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 7750711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:21:40+00:00 2026-06-01T11:21:40+00:00

I have a script that I’m trying to get working. Basically, what I’m trying

  • 0

I have a script that I’m trying to get working. Basically, what I’m trying to do is prevent someone from entering in special characters in to a field.

the function I have is as follows:

var iChars = "!@#$%^&*()+=[];,./{}|<>?;";
if (field1.value.indexOf(iChars) !=-1)

  { 
    alert ("problem")
  }

The issue I’m having is that the field is searching for the exact match to the iChars var instead of matching any single value. For example if I create a var test =”one” and enter “one” into the field, it returns with the error, but if I enter “o” into the field, it does not return anything and just passes through to the next portion of the script – but if i entered “none” or “oneeee” it would push the error through.

Any help on fixing this? I tried looking into arrays for indexOf but didn’t really understand it, so if you are going to suggest it can you please explain in as much detail as possible.

Thanks

  • 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-01T11:21:41+00:00Added an answer on June 1, 2026 at 11:21 am

    You could use…

    var value = field1.value;
    
    for (var i = 0, length = value.length; i < length; i++) {
        if (iChars.indexOf(value.charAt(i)) != -1) {
           alert('Problem!');
           break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that generates images from text using PHP. It's working fine
I have a script that counts the characters in each of my comments, excluding
I have a script that imports a models.py from an app, but it will
I have this script that will let the user download the data from the
I have a script that is working out the width of the screen -225px
I have a script that will run on server daily to download data from
I have a script that retrieves objects from a remote server through an Ajax
I have a script that checks responses from HTTP servers using the PEAR HTTP
I have small script that takes the value from a text input and needs
I have an script that receives an encrypted url and from that generates a

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.