I am complete novice at regex and Javascript. I have the following problem: need to check into a textfield the existence of one (1) or many (n) consecutive *
(asterisk) character/characters eg. *
or **
or ***
or infinite (n) *
. Strings allowed eg. *tomato
or tomato*
or **tomato
or tomato**
or as many(n)*tomato many(n)*
. So, far I had tried the following:
var str = 'a string'
var value = encodeURIComponent(str);
var reg = /([^\s]\*)|(\*[^\s])/;
if (reg.test(value) == true ) {
alert ('Watch out your asterisks!!!')
}
*
anywhere in the word, should it fire the alert? Or only if it's at start and/or end of the string? – Fabrício Matté Jul 30 '12 at 11:27textarea
, or text-input
, value? Or should this be checked word-by-word? – David Thomas Jul 30 '12 at 11:28