Hi frnds.. am new to php.. and my senior asked me to validate the 'Name' field such that user does not enter 'Space' in the beginning.. 'Space' in between their name is allowed.. i searched in google a lot.. but couldn't find the exact code which i need.. the codes which i tried showed a pop-up window when user enters 'Space'.. but i dont need like that.. what i need is, it should show just like a validated field.. i.e, "This field is required".. So can anyone please help me..
Thanks in advance!
using javascript space validation for a textbox
Moderator: General Moderators
Re: using javascript space validation for a textbox
So they have to enter something and besides spaces?
Take the input, trim off the leading and trailing spaces, and make sure you've ended up with something that isn't just an empty string.
Take the input, trim off the leading and trailing spaces, and make sure you've ended up with something that isn't just an empty string.
- Vincent Puglia
- Forum Commoner
- Posts: 67
- Joined: Thu Sep 04, 2003 4:20 pm
- Location: where the World once stood
Re: using javascript space validation for a textbox
if you want a javascript solution:
Code: Select all
function doIt(obj)
{
var notDone = true;
do {
if (obj.value.substr(0,1) == " ")
obj.value= obj.value.substr(1);
else notDone=false;
} while(notDone)
Code: Select all
<form>
<input type='text' placeholder="First Last Name" onblur="doIt(this)">
</form>