Jump to content

Reg Exp not evaluating as expected


brucemand

Recommended Posts

if(textinput.value.match(/[^a-z0-9\s]/g)); { alert(textinput.value.match(/[^a-z0-9\s]/g)); // just to see what alert("alphanum only, pls"); // 'null' = true !!! }
how should i write this snippet to do nothing if it's 'okay' ?
Link to comment
Share on other sites

how should i write this snippet to do nothing if it's 'okay' ?
if(!textInput.value.match(/regExp/)==null){alert("alphanum only!");}

EDIT: remove the semicolon that is after your condiction!

if(codiction);{code to be exec...}

remove the:

;

Link to comment
Share on other sites

Hope that help!
ahh yes, such a BASIC error !! :)thank you !i think my RegExp is still not quite correct though.how do you add BOTH
/[^a-z]/g

and

/[^0-9]/g

and then the meta \s as well !this looks like it's wrong

/[^a-z0-9\s]/g
Link to comment
Share on other sites

okay, thanks it does infact work.there was some other error in the code that was causing the script to fail.EDIT:incidentally; why is this page http://www.w3schools.com/jsref/jsref_match.asp"hidden" :) from the tutorial on Reg Exp at http://www.w3schools.com/jsref/jsref_obj_regexp.aspthere are only;RegExp Object Methods

Method 	Descriptioncompile() 	Compiles a regular expressionexec() 	Tests for a match in a string. Returns the first matchtest() 	Tests for a match in a string. Returns true or false

Link to comment
Share on other sites

A lot of string methods take a regex as an argument, and match() is one of them. They are discussed in the string section. Links to the regex object can be found on those pages. You do find this information on the page you linked to:

. . . "search-and-replace" functions on text
But many readers might not think to look at the string methods based on that.Maybe you could make a suggestion in the suggestions forum.
Link to comment
Share on other sites

##CUT##But many readers might not think to look at the string methods based on that.Maybe you could make a suggestion in the suggestions forum.
is this thread not that ? :)what is the relationship of this forum to the actual W3Schools site ?are you not both staff of the same "employer" ?
Link to comment
Share on other sites

The relation between this forum and the W3Schools site is a link on their site. Since they basically never visit the forums, there's no other relation besides the link.

Link to comment
Share on other sites

The relation between this forum and the W3Schools site is a link on their site. Since they basically never visit the forums, there's no other relation besides the link.
i see, okay.just thought that "In the beginning..." one person (from one side) must have 'spawned the other'.
Link to comment
Share on other sites

Both sites are owned by one business. The Board is a way for users of the Schools to interact and basically do what we do. The suggestions forum is the only place the owners claim to visit. They do drop in from time to time, but it looks like the 2 most active admins have not been here since March.

Link to comment
Share on other sites

Both sites are owned by one business. The Board is a way for users of the Schools to interact and basically do what we do. The suggestions forum is the only place the owners claim to visit. They do drop in from time to time, but it looks like the 2 most active admins have not been here since March.
i hope that is "good news" and that they're planning better things !or maybe they see that the current admins are already doing a very good job and they trust the delegations that have been distributed.i imagine i will "graduate" one day and visit this place less & less, but i sure would like to see it grow and become as well-known as the likes of Facebook & Yahoo, etc !! :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...