It is a regular expression that tests a field to check if it is blank, or only contains spaces. s matches a single white space character, including space, tab, form feed and line feed. The * tells it to match it 0 or more times. The .test part tells it what you are testing (in my example, we are testing the form field 'mytextarea'). Had we been testing a variable, it would have been .test(varname).
but it also causes me to ask some more questions :rolleyes:
I'm going to make some assumptions....
so please correct me if I am wrong about them.
I assume that the forward slashes are used as a "container" for the expression (?)
But what I am having difficulty with is the [B][COLOR=crimson][SIZE=3]^[/SIZE] [/COLOR][/B] and the [B][COLOR=crimson][SIZE=3]$[/SIZE] [/COLOR][/B]
I understand that the first tests the beginning of the input, and the second one tests the end of the input.
but...
if [B][COLOR=crimson][SIZE=3]s*[/SIZE] [/COLOR][/B] tests for all instances of spaces, tabs, form feeds and line feeds....
then is it necessary (required) to use [B][COLOR=crimson][SIZE=3]^[/SIZE] [/COLOR][/B] and [B][COLOR=crimson][SIZE=3]$[/SIZE] [/COLOR][/B] at all in this case?
I guess I'm asking if this would work just as effectively if it was just written like this:
@pyroJul 24.2003 — #Yes, everything between the / / are regexp expressions.
/s*/ howerver, is not the same as /^s*$/. If you were to use /s*/, the if statement would return true if it encounters any spaces. ie. 'testing this' would return true (and thus alert the users, and return false on the form, causing it not to submit).
If we use /^s*$/, we are checking the field like this:
If the form starts with a space, contains only spaces, and ends with a space, alert the user.
If we use /s*/, we are checking the field like this: