www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Vaildation of Characters

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    32

    resolved [RESOLVED] Vaildation of Characters

    Can Any One Tell Me A If Statement That Will Check For These Characters
    Code:
    \/:*?"<>|
    Thank You

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,276
    An essay of search for one of these characters in strings...
    Code:
    
    // Multiple strings to split for tests
    var str="hello word !@<script>@How are you ?@Well 5/5 !@2*2 = 4@...\"...@..|..@Good luck !".split('@');
    
    // The test for one of the following characters:  \/:*?"<>|
    for (var l=str.length,i=0;i<l;i++) 
    	alert(str[i]+(/[\\\/:\*\?\"<>]/.test(str[i])?' contains':' does not contain ')+' one of the indicated (\/:*?"<>|) characters !');
    All this characters (except colon, less and more) must be escaped with a backslash in the character class delimiter by the two square brakets...
    Last edited by 007Julien; 07-09-2012 at 11:31 PM.

  3. #3
    Join Date
    Jul 2012
    Posts
    32
    okay, is there a to put it in a if statement?(so after i validate if they typed something in or not i can check to see if they have a invalid characters entered.). Thank You For The Reply.

  4. #4
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    607
    Code:
    InPut=prompt('What?','');
    if (InPut.match(/^.*?[\\\/\:\*\?\"\<\>\|].*?$/)) {
     alert('Found one.');
    } else {
     alert('None found.');
    }

  5. #5
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    607
    Quote Originally Posted by jalarie View Post
    Code:
    InPut=prompt('What?','');
    if (InPut.match(/^.*?[\\\/\:\*\?\"\<\>\|].*?$/)) {
     alert('Found one.');
    } else {
     alert('None found.');
    }
    The caret (^) at the beginning forces the pattern to start at the beginning of the string.
    The dollar sign ($) at the end forces the pattern to go all the way to the end of the string.
    The dot-star-question-mark (.*?) sets allow us to ignore leading and trailing characters.
    The square brackets ([]) surround multiple individual characters to seek.
    Each of the individual characters is preceeded by a back-slash (\) so that it doesn't have any special meaning.

  6. #6
    Join Date
    Jul 2012
    Posts
    32
    That Seems To Be Just What I Needed, Thank You So Much

    and I Went To Your WebSite And Found Your Safe Sex Quote To be Very True

  7. #7
    Join Date
    Jul 2012
    Posts
    32
    That Helps Me A Lot Thank You Once Again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles