SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need to check a string to make sure it includes a period "." and does not include an "@" or spaces but it doesn't matter what else is in it.

    Any help is appreciated.

    Thanks in advance.

  2. #2
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    VBScript (Client-Side) or JavaScript?
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  3. #3
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thansk for the quick reply - javascript

  4. #4
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ack.

    Sorry, but i'm afraid I can't help much. With VBScript and stuff I can do it in a snap, but my JavaScript skills are VERY VERY rusty.

    I'll turn this thread over to one of our resident JS gurus now.

    Sorry that I couldn't help.

    Good luck with your Scripting!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  5. #5
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys,

    To detect if a string contains a character, you can use indexOf. Here's an example:

    Code:
    str="this is a new string with @ and, of course, spaces";
    
    if(str.indexOf(".")==-1 || str.indexOf(" ")!=-1 || str.indexOf("@")!=-1){
    alert('This string is not in the correct format');
    }
    Hope that helps,
    aDog

  6. #6
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also use regular expression in Javascript to check whether a string contains " . " and anything else other than "@"

    <script language="javascript1.2">
    re = /^[\w\d\.]+.[\w\d\.]+$/
    myString = "abc@ew e";
    if (re.test(myString)) {
    alert("valid string!");
    }
    else{ alert("invalid string!"); }

    myString2 = "accept.this";
    if (re.test(myString2)) {
    alert("valid string!");
    }
    else{ alert("invalid string!"); }

    </script>

    This regular expression accepts any letter or digit and at least a period. Probably not very complete, but you can go here for more reference: http://developer.netscape.com/docs/m...ide/regexp.htm


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
  •