Click here to Skip to main content
12,063,909 members (60,910 online)
Click here to Skip to main content
Add your own
alternative version

Stats

78K views
2.7K downloads
46 bookmarked
Posted

An ASP.NET Spell Checker for a Textbox

, 1 Jul 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An ASP.NET spell checker for text entered into a textbox.

Screenshot - checkspellingscreenshot.jpg

Introduction

I created my own blog at http://www.bid4binary.com and was finding that I was adding a lot of articles with spelling mistakes and then having to go back and modify these articles later (sometimes only after my wife or a friend pointed them out - ouch!). I really needed something that would check my spelling before posting the article so that I could just add it and be done with it.

Background

I did quite a bit of searching on the web and found many controls that would do this, but unfortunately, these were quite expensive (especially for a South African). Still others used Google APIs that seem to have been removed, or Microsoft Word APIs that are more suited for Windows applications and not web applications.

I then found a gem here on CodeProject by Vasantha Mohan (http://www.codeproject.com/asp/spell_check.asp) that describes how to use a dictionary file to check spelling in ASP. This was able to provide a good base for me to convert to ASP.NET and make some changes more suited for my project. I did not use his method to insert hard-returns as I am simply checking the text, not the formatting. In addition, I added an enhancement whereby the user can manually type an alternative word if no suitable suggestion was found by the spell checker, and modified the code so that the function only searches for alternatives beginning with the same letter as the word being checked - speeding things up significantly.

It's not perfect, but it works well - some further enhancements I'd like to see would be some kind of progress indicator so you know what it's doing while waiting, and the ability to add words to the dictionary file.

Using the code

The downloadable zip file contains five files:

  1. dict-large.txt - Contains a list of words to check against, place this in the same directory as the pages below.
  2. TestSpellCheck.aspx - This is the page you need to start with, it contains the textbox where you should enter the text to be checked for spelling errors.
  3. TestSpellCheck.aspx.vb - Nothing useful here, just a standard code-behind file.
  4. SpellSuggest.aspx - This is the page that displays the incorrect words and allows you to select an alternative or manually type an alternative.
  5. SpellSuggest.aspx.vb - Here's where the magic happens.

I am not going to show any code here as it is very well commented in the source code and it will be more useful to simply describe what it does. Feel free to contact me should you need any assistance.

In TestSpellCheck, we take the text that the user entered into the textbox, trim off any leading or trailing spaces, and then open a new window, passing this trimmed text as a URL parameter.

In SpellSuggest, we split the text into an array of individual words and check these against our dictionary file. For the current word, we only load each word from our dictionary beginning with the same letter. We then check that we have valid characters in the word to check, and if not, simply skip to the next; we then check if it's a number, and skip to the next if it is; next, we check if it's a valid word and skip if it is.

If by now we have not skipped, then our word is not in our dictionary, and we stop to allow the user to select an alternative from a list of suggestions, or manually type an alternative.

We also allow the user to cancel the check at any time. If they do this, we replace the part that they have already checked and leave the rest alone.

If they have reached the end of the checking, we show them a message, replace the original text, and close the SpellSuggest window.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

mikvos
Web Developer
South Africa South Africa
No Biography provided

You may also be interested in...

Comments and Discussions

 
Suggestionfix to make NEXT, STOP buttons proceed beyond first word Pin
Member 104400774-Dec-13 8:11
memberMember 104400774-Dec-13 8:11 
QuestionWant c# code for SpellCHecking Pin
rajender120318-Jul-12 19:52
memberrajender120318-Jul-12 19:52 
Questionurgent Pin
amr rabie17-Oct-11 11:24
memberamr rabie17-Oct-11 11:24 
GeneralDoes not work for some words.. Pin
AmMadhav3-Nov-09 11:45
memberAmMadhav3-Nov-09 11:45 
GeneralI am so sorry, but I'm unable to support the code anymore Pin
mikvos20-Aug-09 5:18
membermikvos20-Aug-09 5:18 
GeneralHi Pin
pulokesh20-Aug-09 5:09
memberpulokesh20-Aug-09 5:09 
GeneralRe: Hi Pin
mikvos20-Aug-09 5:14
membermikvos20-Aug-09 5:14 
GeneralNext and Stop buttons don't work Pin
MLightsOut3-Aug-09 12:47
memberMLightsOut3-Aug-09 12:47 
GeneralRe: Next and Stop buttons don't work Pin
twitChingX22-Oct-09 1:14
membertwitChingX22-Oct-09 1:14 
QuestionWorks partially. Can someone please help me with this?????????????????????? Pin
somepi22-Apr-09 19:16
membersomepi22-Apr-09 19:16 
AnswerRe: Works partially. Can someone please help me with this?????????????????????? Pin
Ladybolt17-Aug-09 17:11
memberLadybolt17-Aug-09 17:11 
GeneralIncorrect suggestions Pin
mayankagarwa;22-Apr-09 17:55
membermayankagarwa;22-Apr-09 17:55 
GeneralIncorrect suggestions Pin
mayankagarwa;22-Apr-09 17:55
membermayankagarwa;22-Apr-09 17:55 
GeneralMy vote of 1 Pin
Imparatorvolkan31-Mar-09 12:56
memberImparatorvolkan31-Mar-09 12:56 
GeneralExcellent Pin
AmMadhav25-Mar-09 5:51
memberAmMadhav25-Mar-09 5:51 
QuestionHelp Pin
Joshua Paul Landry15-Mar-09 9:57
memberJoshua Paul Landry15-Mar-09 9:57 
AnswerRe: Help Pin
GB 195320-Jun-09 16:42
memberGB 195320-Jun-09 16:42 
QuestionC# Version availible? Pin
Sunil1286-Mar-09 5:02
memberSunil1286-Mar-09 5:02 
GeneralSpelling Checker and Master page Pin
Member 452956426-Aug-08 6:27
memberMember 452956426-Aug-08 6:27 
GeneralGreat article, but single quoto did not work Pin
Tony Dong18-Feb-08 8:44
memberTony Dong18-Feb-08 8:44 
GeneralAvoid popup Pin
koese12-Aug-07 20:32
memberkoese12-Aug-07 20:32 
GeneralRe: Avoid popup Pin
mikvos12-Aug-07 20:59
membermikvos12-Aug-07 20:59 
GeneralVery Gud job Pin
Mukesh_B10-Jul-07 21:58
memberMukesh_B10-Jul-07 21:58 
GeneralSweet Pin
Curt Ophoven10-Jul-07 7:10
memberCurt Ophoven10-Jul-07 7:10 
GeneralRe: Sweet Pin
mikvos10-Jul-07 18:57
membermikvos10-Jul-07 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.160204.4 | Last Updated 2 Jul 2007
Article Copyright 2007 by mikvos
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid