473,670 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

special character check in text box

2 New Member
Hi guys,

I want to check whether the user has entered any special characters in a text box.

If the user enters, i want to display an alert message stating that he cant enter a special character (like Ç).

I have written a code wherein i am specifying the list of characters that are not allowed.

It would be better if i can give a list of characters that are allowed instead of list of characters that are not allowed. And check whether any of the character in the text box, is not in the list.

Can u guys suggest me how to go about doing it.

here is my piece of code:

var iChars = "!@#$%^&*() +=-[]\\\';,./{}|\":<>Ç?";
for (var i = 0; i < document.basic_ submit_form.com p_name.value.le ngth; i++) {
if (iChars.indexOf (document.basic _submit_form.co mp_name.value.c harAt(i)) != -1) {
errorMsg += "* Company name entered has special characters. Please remove them and try again.\n";
noOfErr ++;
}
}
Aug 7 '07 #1
3 14669
dmjpro
2,476 Top Contributor
Hi guys,

I want to check whether the user has entered any special characters in a text box.

If the user enters, i want to display an alert message stating that he cant enter a special character (like Ç).

I have written a code wherein i am specifying the list of characters that are not allowed.

It would be better if i can give a list of characters that are allowed instead of list of characters that are not allowed. And check whether any of the character in the text box, is not in the list.

Can u guys suggest me how to go about doing it.

here is my piece of code:

var iChars = "!@#$%^&*() +=-[]\\\';,./{}|\":<>Ç?";
for (var i = 0; i < document.basic_ submit_form.com p_name.value.le ngth; i++) {
if (iChars.indexOf (document.basic _submit_form.co mp_name.value.c harAt(i)) != -1) {
errorMsg += "* Company name entered has special characters. Please remove them and try again.\n";
noOfErr ++;
}
}

Welcome to TSDN!!!

Do u know regular expression?
Then it wud be better to handle.
You can check the key value range.

Expand|Select|Wrap|Line Numbers
  1. //in IE ...
  2. event.keyCode
  3. //In others
  4. event.which
  5.  
Aug 7 '07 #2
jeyabarani
2 New Member
But I want to allow the user to enter the special characters in the text field.
The alert message will be shown only when the form is submitted.

As i understand, keyCode checks the key that is typed.

Can u suggest with unicode?


Thanks
Aug 7 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
But I want to allow the user to enter the special characters in the text field.
The alert message will be shown only when the form is submitted.

As i understand, keyCode checks the key that is typed.

Can u suggest with unicode?
Use regular expressions, but check when you submit the form.

See tutorial link and specifically for Javascript.

Use the form onsubmit event handler to call a validation function.
Aug 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
47811
by: Pikkel | last post by:
i'm looking for a way to replace special characters with characters without accents, cedilles, etc.
3
17193
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in oracle database. When i retrieve the data, some of the special characters have been changed to ??? and also
3
2362
by: ATH0 | last post by:
How to search for special character { } and how to count them.. I got field called text ( undefined length ) and in this field you must define "{" as start and "}" as end of some text line. If you can find both {} then you have to count them. example: bla bla bla {bla { asd asd} Result:
50
4328
by: The Bicycling Guitarist | last post by:
A browser conforming to HTML 4.0 is required to recognize &#number; notations. If I use XHTML 1.0 and charset UTF-8 though, does &eacute; have as much support as é ? Sometimes when I run the TIDY utility on my code, it replaces my character notations with weird looking things I don't recognize. Also, when I converted to UTF-8 from ISO-8859-1, I discovered many special characters
5
8612
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
8
3661
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
25
5354
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found out that addslashes() can be used escape some characters, but I'm having some more problems with for instance ä, å and µ (since the text is scientifical) Now some people also throw in htmlspecialchars() to convert those to HTML entities, but some...
1
4562
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file, 2. Text checks for max. length of the field & whether the field is mandatory or optional Example:
7
4904
by: Trac Bannon | last post by:
When I load XML from a file into a dotNet XMLDataDocument, the UTF-8 codes are resolved but the 5 special XML entities are not. How can I force those 5 special character types to be translated?
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.