Jump to content

eregi


Daney11

Recommended Posts

Hey guys, Im using this

 

if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['member_firstname'])))) {

 

However, users are allowed to enter as many spaces as they want, example

 

"  Da  N  e"

 

I want it so that the user can only enter one space in the form, how would i go about doing this?

 

Thanks

Link to comment
Share on other sites

You might try something on the actual form page in javascript instead.

 

Something like:

 

<html>
<head>
<script>

var spaces = 0;
var theID;

function watchKeys(e,id) {

theID = id;

if(window.event) { // IE
  		
	key = e.keyCode;
  	
}

else if(e.which) { // Netscape/Firefox/Opera
  
  		key = e.which;

  	}

	if(key == 32) { //spacebar


	if(spaces == 1) {

		val = document.getElementById(theID).value;
		document.getElementById(theID).value = val.substring(0, val.length-1);


	}	

	else {

		spaces++;

	}


}

}
</script>
</head>
<body>

<input type="text" id="myText" name="myText" onkeypress="return watchKeys(event,this.id);">
</body>
</html>

 

I tested this a bit after I made it, it's buggy, but it's a start for you if you want to go that route.

Link to comment
Share on other sites

Hey guys, Im using this

 

if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['member_firstname'])))) {

 

However, users are allowed to enter as many spaces as they want, example

 

"   Da  N   e"

 

I want it so that the user can only enter one space in the form, how would i go about doing this?

 

Thanks

 

try this...

preg_match_all('/\s/', $string, $matches, PREG_OFFSET_CAPTURE, 3);
if(!preg_match("|^[a-z0-9]$|i",$string)||count($matches)>1){
print "You have exeeded 1 space, or your string is not alpha-numerical.";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.