• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 36
  • Last Modified:

Javascript alphabetic text validation doesn't prevent numeric values.

Javascript alphabetic text validation doesn't prevent numeric values. This is my code for the validation
		   
    if (/^([a-zA-Z\s]+ [a-zA-Z\s])$/.test(z))
     {
    return (true)
     }
   else{
    event.preventDefault();
    alert("Please insert characters only!")
    return (false)
   }
  	   

Open in new window

I can't find  the mistake.
0
pink glitter
Asked:
pink glitter
1 Solution
 
leakim971PluritechnicianCommented:
look fine for me, what is your input?
look fine
1
 
pink glitterAuthor Commented:
My input is a textbox. I typed "123" in it and it got accepted...
0
 
leakim971PluritechnicianCommented:
also you can replace your whole code by :
return /^([a-zA-Z\s]+ [a-zA-Z\s])$/.test(z);

123 return false
1
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Sam WallisIt/Web ManagerCommented:
It looks fine to me too.
Have you confirmed the script is actually firing when you hit submit?
0
 
Julian HansenCommented:
My input is a textbox. I typed "123" in it and it got accepted...
accepted by what?

What is that code snippet reporting back to.
0
 
pink glitterAuthor Commented:
The code snippet was in a wrong place, that's why it didn't work. Anyway thank you all for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now