# Checking if a certain character has been entered

**URL:** <https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564>\
**Category:** Uncategorized\
**Created:** [August 28, 2003, 5:49am UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564 "2003-08-28T05:49:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![blah\_de\_blah](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@blah\_de\_blah](https://forum.kirupa.com/u/blah_de_blah)\
**Post date:** [August 28, 2003, 5:49am UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/1 "2003-08-28T05:49:17Z")

</div>

How would you check if a certain character has been entered in a form field? An example would be an e-mail form…I want to check if it has the ‘@’ character. What command would you use? thanks

Btw, just give me the command and not the whole code for now so i can try it out myself 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 6:02am UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/2 "2003-08-28T06:02:56Z")

</div>

I cheat and use the Form Validation behavior by Yaromat. I don’t bother trying to reinvent the wheel, and I HATE coding in Javascript. :}

Dreamweaver Extensions at [www.yaromat.com](http://www.yaromat.com)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 1:25pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/3 "2003-08-28T13:25:08Z")

</div>

Yeah that would be good for a last resort 😛 but i want to learn this so any other ideas?!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 1:59pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/4 "2003-08-28T13:59:45Z")

</div>

You’ll want to do it client-side, before the form actually gets submitted to the server, so Javascript is the best way to go. You could do it server side, after submit, then return to the form if invalid, but that’s clumsy for the user.

DigitalPimp is the resident Javascript whiz, when I checks in he should be able to at least point you in the right direction. I can code ASP script in my sleep, but I only know enough Javascript to be dangerous. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 2:39pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/5 "2003-08-28T14:39:14Z")

</div>

For checking whether there is an @ in a string with JS…

```auto

if(yourEmailString.indexOf("@") != 1){
//email is correct
processForm();
}else{
alert("That isn't a valid email adress.");
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 2:43pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/6 "2003-08-28T14:43:37Z")

</div>

If you take the script that njs just posted (thank-you) and make it a function, you can then call it from an onSubmit command in the FORM tag.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 2:51pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/7 "2003-08-28T14:51:40Z")

</div>

So should it be like this?

```php

function validation() {
if(email.value.indexOf("@") != 1){
        //email is correct
        processForm();
}else{
        alert("That isn't a valid email adress.");
}
}

```

Is processForm already a javascript function? I can’t test it because my server thing is very slow :-\ Oh yea i changed ‘youremailString’ to ‘email.value.indexOf’ where email is the form name. Would that work? thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 3:03pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/8 "2003-08-28T15:03:09Z")

</div>

no… processForm was just a function which submitted the form.

Unfortunately I don’t really know JavaScript. I just pulled that out of Flash AS.

Also, you don’t need a server to test JavaScript. You can just open the pages in IE or Mozilla or whatever browser you use.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 3:05pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/9 "2003-08-28T15:05:46Z")

</div>

Oh ok, well i’ll try it. I have to upload it to a server because i use php for the mail form :-\ Thanks for the help though njs and abzoid

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2003, 3:22pm UTC](https://forum.kirupa.com/t/checking-if-a-certain-character-has-been-entered/29564/10 "2003-08-28T15:22:38Z")

</div>

I think i have found a good email validation code. But its pretty confusin :-\ I’ll work on it though…thanks 🙂
