How to display error message when string entered together with the characters outside the A-Z a-z 0-9?

Try these:

<input type="text" id="txt1" name="txt1" size="20" value="" onchange="if (!/[A-Za-z\d]/.test(this.value)) alert('Invalid data!');" />

Sorry, if I input text like this "Test's or Test.s" it don't show error message :(.

I try use indexOf() it work but to many code added... :(

Anyidea ???

Here you go...

<input type="text" id="txt1" name="txt1" size="20" value="" onchange="if (!/[A-Za-z]+([0-9])/.test(this.value)) alert('Invalid data!');" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.