SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: RegExp problem

  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RegExp problem

    Hello,

    I've written a little javascript to check a domain if it contains invalid chars... Everything works, except the fact that it doesn't detect a '_', and a domain may not contain any '_'.

    I have this:

    Code:
    	if( (/^\w+([\-]?\w+)+$/.test(domainstr)) && domainstr!=""){
    		return true;
    	}
    Some examples of domainstrings:
    abcd123 => valid (works)
    abc-123 => valid (works)
    abc.123 => invalid (works)
    abc_123 => invalid (doesn't work...)

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace every instance of \w with [a-zA-Z0-9] because the underscore (_) is a valid word character according to regex rules.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works fine.

    Thank you very much!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •