php - need a regular expression in javascript which allows text having special character * in the begining of input data -
i new regex. need regex javascript code allows special character * in beginning of text input, not anywhere else in text.
example : should allow *text, should not allow *text*abcd
i need similar regex php well.
i have tried using "/^\s*/", doesn't work. anyways dont have anyidea of regex. have started learning it.
thanks dora
part of learning how use regex knowing when don't need it. in case solution without regex suffice, php:
if (strrpos($str, '*') > 0) { // invalid position of * } for javascript:
if (str.lastindexof('*') > 0) { // invalid position * } it finds last position of special character; if appears in string , not first character, code inside condition gets executed.
Comments
Post a Comment