Jump to content

Recommended Posts

What im trying to achieve is not to let the users enter spaces or new lines and send them to database via ajax..

 

so how can echo a message that the user must enter something when he enters just line breaks or spaces in a textarea?

 

i tried checking if the textarea value is null , = "" or = " " but thats just not what i need...

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/228904-remobe-from-textareas/
Share on other sites

I don't know of the standard practice for this, but you could do an explod on the text area input, and see how big the resulting array is, using space as the delimeter.

 

If there is two items in the array, then the use must have entered a space, otherwise if it's just one thing long, there is no spaces in there.. As for line breaks, I'm not sure..

 

Denno

Are you trying to prevent submission of the form if the field has nothing but spaces or line feeds? In other words, the user has to enter actual text?

 

 

thats exactly what im trying to do.

 

I don't know of the standard practice for this, but you could do an explod on the text area input, and see how big the resulting array is, using space as the delimeter.

 

If there is two items in the array, then the use must have entered a space, otherwise if it's just one thing long, there is no spaces in there.. As for line breaks, I'm not sure..

 

Denno

if i explode the string using space " " then the user can enter spaces between words in a single line so i dont get how this would work properly in my problem , also the user can enter twice or more times lines , what i want is to prevent the user from entering spaces only or lines only without a single letter.

If you are looking to strip new lines from going into the database then something like this?

 

$remove = str_replace("\n", " ", $string);

 

It will strip new line breaks from the $string which will be your variable holding your textarea data.

 

i want to strip whitespaces and new lines when there is letter inside the textarea..

 

This should work

 

if(empty(trim($value)) {

//Made up of just white spaces

} else {

//Has other content

}

yeap it works but how can i make it work in javascript?

this is what i got

var string;
function IsNumeric(input){
	var RE = /^-{0,1}\d*\.{0,1}\d+$/;
	return (RE.test(input));
}
function _empty(string){
	string = $.trim(string);
	if(!IsNumeric(string)){ return string.length = -1; }
	return FALSE;
}
	else if (_empty(msg)){
	$('#error').show();
	$('#error').html("Error.");
}

 

it seems to work but on the second click it doesnt recognise the value and i have to refresh..

thanks

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.