Avatar billede maddoggy Nybegynder
03. marts 2008 - 09:45 Der er 19 kommentarer

Hvordan kan man få de danske tegn til at virke ved en tilmeld?

Hejsa

sidder og har et meget dumt/trals problem, med at jeg ikke kan finde nogen måde hvor på jeg kan tillade en bruger at oprette sig med ÆØÅ i deres brugernavn.

Hvis der var en som kunne give et svar på problemet ville jeg være en glad mand :-)

Selve kode er her: (mener at det er det hele)

$area = "public";
include("./_include/core/main_start.php");

class CIndex extends CHtmlBlock
{
    var $message = "";
    function action()
    {
        global $g;
        global $l;

        $cmd = get_param("cmd", "");

        if ($cmd == "please_login")
        {
            $this->message = $l['join.php']['please_login'] . "<br>";
        }
        if ($cmd == "sent")
        {
            $this->message = $l['join.php']['was_sent'] . "<br>";
        }
        elseif ($cmd == "login")
        {
            $name = get_param("user", "");
            $password = get_param("password", "");

            $this->message = "";
            $id = DB::result("SELECT user_id FROM user WHERE name=" . to_sql($name, "Text") . " and (password=" . to_sql($password, "Text") . " OR password=" . to_sql(md5($password), "Text") . ");");
            if ($id == 0)
            {
                $this->message .= $l['join.php']['incorrect_username'] . "<br>";
            }

            if ($this->message == "")
            {
                set_session("user_id", $id);
                set_session("user_id_verify", $id);
                #print_r($_SESSION);
                if (get_param("remember", "") != "")
                {
                    set_cookie("c_user", $name, -1);
                    set_cookie("c_password", $password, -1);
                }
                else
                {
                    set_cookie("c_user", "", -1);
                    set_cookie("c_password", "", -1);
                }

                DB::execute("UPDATE user SET last_ip=" . to_sql($_SERVER['REMOTE_ADDR'], "Text") . " WHERE user_id=" . $id . "");

                redirect("home.php");
            }
        }
        elseif (get_cookie("c_user") != "" and get_cookie("c_password") != "")
        {
            if (get_session("user_id") != "")
            {
                redirect("home.php");
            }

            $name = get_cookie("c_user");
            $password = get_cookie("c_password");

            $this->message = "";
            $id = DB::result("SELECT user_id FROM user WHERE name=" . to_sql($name, "Text") . " and (password=" . to_sql($password, "Text") . " OR password=" . to_sql(md5($password), "Text") . ");");
            if ($id == "")
            {
                $this->message .= $l['join.php']['incorrect_username'] . "<br>";
            }

            if ($this->message == "")
            {
                set_session("user_id", $id);
                set_session("user_id_verify", $id);

                DB::execute("UPDATE user SET last_ip='" . $_SERVER['REMOTE_ADDR'] . "' WHERE user_id=" . $id . "");

                redirect("home.php");
            }
        }

        if (get_session("user_id") != "")
        {
            redirect("home.php");
        }

        global $m;
        $m = $this->message;
    }
    function parseBlock(&$html)
    {
        global $g_info;
        foreach ($g_info as $k => $v) $html->setvar($k, $v);
        $html->setvar("login_message", $this->message);
        parent::parseBlock($html);
    }
}

class CJoinForm extends CHtmlBlock
{
    var $message = "";
    var $login = "";

    function init()
    {
        global $g;
        global $l;
        global $gc;

        $name = get_param("join_handle", "");
        $pass = get_param("join_password", "");
        $pass2 = get_param("verify_password", "");
        $mail = get_param("email", "");
        $mail2 = get_param("verify_email", "");

        $this->message = "";

        if (strlen($name) < 4 or strlen($name) > 20 or strpos($name, "'") !== false)
        {
            $this->message .= $l['join.php']['another_username'] . "<br>";
        }

        if ($mail != $mail2 or strlen($mail) > 100 or !preg_match("/^[a-zA-Z-_\.0-9]{1,100}@[a-zA-Z-_\.0-9]{1,100}\.[a-zA-Z-_\.0-9]{1,100}$/", $mail))
        {
            $this->message .= $l['join.php']['incorrect_email'] . "<br>";
        }

        if ($pass != $pass2 or strlen($pass) > 15 or strlen($pass) < 6 or strpos($pass, "'") !== false)
        {
            $this->message .= $l['join.php']['incorrect_password'] . "<br>";
        }

        if (DB::result("SELECT user_id FROM user WHERE name=" . to_sql($name, "Text") . ";") != "")
        {
            $this->message .= $l['join.php']['exists_username'] . "<br>";
        }

        if (DB::result("SELECT user_id FROM user WHERE mail=" . to_sql($mail, "Text") . ";") != "")
        {
            $this->message .= $l['join.php']['exists_email'] . "<br>";
        }

        $month = (int) get_param("month", 1);
        $day = (int) get_param("day", 1);
        $year = (int) get_param("year", 1980);

        if ($month < 1 or $month > 12 or $day < 1 or $day > 31 or $year < 1906 or $year > date("Y") - $g['options']['users_age'] + 1)
        {
            $this->message .= $l['join.php']['incorrect_date'] . "<br>";
        }

        if ($this->message == "")
        {
            set_session("j_name", $name);
            set_session("j_password", $pass);
            set_session("j_mail", $mail);
            set_session("j_month", $month);
            set_session("j_day", $day);
            set_session("j_year", $year);
            set_session("j_country", get_param("country", 1));
            set_session("j_orientation", get_param("orientation", 1));

            if ($g['options']['fast_join'] == "N" and isset($gc) and $gc) redirect("join_space.php");
            elseif ($g['options']['fast_join'] == "N") redirect("join2.php");
            else
            {
                $this->add_user();
                #echo get_session("user_id");
                redirect("home.php");
            }
        }
    }
    function add_user()
    {
        $partner = (int) get_session("partner");
        global $g;
        DB::execute("
            UPDATE partner SET
            account=(account+" . to_sql($g['options']['partner_price_user'], "Number") . "),
            summary=(summary+" . to_sql($g['options']['partner_price_user'], "Number") . "),
            count_users=(count_users+1)
            WHERE partner_id=" . $partner . "
        ");

        $p_partner = DB::result("SELECT p_partner FROM partner WHERE partner_id=" . $partner . "");

        $plus = ($g['options']['partner_percent_ref'] / 100) * $g['options']['partner_price_user'];
        DB::execute("
            UPDATE partner SET
            account=(account+" . $plus . "),
            summary=(summary+" . $plus . ")
            WHERE partner_id='" . $p_partner . "'
        ");

        $country = DB::result("SELECT country_title FROM geo_country WHERE country_id=" . to_sql(get_session("j_country"), "Number") . "");

        DB::execute("INSERT INTO email SET mail=" . to_sql(get_session("j_mail"), "Text") . "");
        DB::execute("
            INSERT INTO user
            SET
            partner=" . $partner . ",
            gold_days=0,
            name=" . to_sql(get_session("j_name"), "Text") . ",
            orientation=" . to_sql(get_session("j_orientation"), "Number") . ",
            p_orientation=" . to_sql(DB::result("SELECT search FROM const_orientation WHERE id=" . to_sql(get_session("j_orientation"), "Number")), "Number") . ",
            gender=" . to_sql(DB::result("SELECT gender FROM const_orientation WHERE id=" . to_sql(get_session("j_orientation"), "Number")), "Text") . ",
            mail=" . to_sql(get_session("j_mail"), "Text") . ",
            password=" . to_sql($g['options']['md5'] == "Y" ? md5(get_session("j_password")) : get_session("j_password"), "Text") . ",
            country_id=" . to_sql(get_session("j_country"), "Number") . ",
            country=" . to_sql($country, "Text") . ",
            birth=" . to_sql(get_session("j_year") . "-" . get_session("j_month") . "-" .  get_session("j_day"), "Text") . ",
            horoscope=" . to_sql(zodiac(get_session("j_year") . "-" . get_session("j_month") . "-" .  get_session("j_day")), "Number") . ",
            p_horoscope=0,
            active='Y',
            active_code='',
            hide_time='0',
            register='" . date('Y-m-d H:i:s') . "',
            last_visit='" . date('Y-m-d H:i:s') . "',
            last_ip='',
            set_email_mail='2',
            set_email_interest='2'
        ");

        global $user_id;
        $user_id = DB::insert_id();

        DB::execute("
            INSERT INTO userinfo
            SET
            user_id=" . $user_id . "
        ");

        DB::execute("
            INSERT INTO userpartner
            SET
            user_id=" . $user_id . "
        ");

        DB::execute("DELETE FROM zforum_users WHERE id=".$user_id.";");
        DB::execute("
            INSERT INTO zforum_users
            (id,username, group_id, password, email, email_setting, save_pass, registered)
            VALUES(".
            $user_id.",".
            to_sql(get_session("j_name"), "Text").
            ", 4, ".
            to_sql(get_session("j_password"), "Text").
            ", ".
            to_sql(get_session("j_mail"), "Text").
            ", 1 , 1 ,1".
            ");"
        );

        $subject = DB::result("SELECT subject FROM email_auto WHERE note='join'");
        $text = DB::result("SELECT text FROM email_auto WHERE note='join'");
        $subject = str_replace("{title}", $g['main']['title'], $subject);
        $text = str_replace("{title}", $g['main']['title'], $text);
        $text = str_replace("{name}", get_session("j_name"), $text);
        $text = str_replace("{password}", get_session("j_password"), $text);
        send_mail(
            get_session("j_mail"),
            $g['main']['info_mail'],
            $subject,
            $text
        );

        #session_unset();
        set_session("user_id", $user_id);
        set_session("user_id_verify", $user_id);
    }
    function parseBlock(&$html)
    {
        global $g;
        global $g_info;
        global $l;

        foreach ($g_info as $k => $v) $html->setvar($k, $v);

        $name = get_param("join_handle", "");
        $pass = get_param("join_password", "");
        $pass2 = get_param("verify_password", "");
        $mail = get_param("email", "");
        $mail2 = get_param("verify_email", "");

        $html->setvar("join_handle", $name);
        $html->setvar("join_password", $pass);
        $html->setvar("verify_password", $pass2);
        $html->setvar("email", $mail);
        $html->setvar("verify_email", $mail2);
        if ($name != "") $html->setvar("join_message", $this->message);

        $m = array(
            1 => isset($l['all']['january']) ? $l['all']['january'] : 'Januar',
            2 => isset($l['all']['february']) ? $l['all']['february'] : 'Februar',
            3 => isset($l['all']['march']) ? $l['all']['march'] : 'Marts',
            4 => isset($l['all']['april']) ? $l['all']['april'] : 'April',
            5 => isset($l['all']['may']) ? $l['all']['may'] : 'Maj',
            6 => isset($l['all']['june']) ? $l['all']['june'] : 'Juni',
            7 => isset($l['all']['july']) ? $l['all']['july'] : 'Juli',
            8 => isset($l['all']['august']) ? $l['all']['august'] : 'August',
            9 => isset($l['all']['september']) ? $l['all']['september'] : 'September',
            10 => isset($l['all']['october']) ? $l['all']['october'] : 'October',
            11 => isset($l['all']['november']) ? $l['all']['november'] : 'November',
            12 => isset($l['all']['december']) ? $l['all']['december'] : 'December',
        );

        $html->setvar("month_options", h_options($m, get_param("month", 1)));
        $html->setvar("day_options", n_options(1, 31, get_param("day", 1)));
        $html->setvar("year_options", n_options(date("Y") - $g['options']['users_age_max'], date("Y") - $g['options']['users_age'] + 1, get_param("year", date("Y") - $g['options']['users_age_max'])));

        $html->setvar("country_options", DB::db_options("SELECT country_id, country_title FROM geo_country WHERE country_id in (1,2,3)" , 1) . DB::db_options("SELECT country_id, country_title FROM geo_country ORDER BY country_title" , ""));
        $html->setvar("orientation_options", DB::db_options("SELECT id, title FROM const_orientation", get_param("orientation", "")));
        parent::parseBlock($html);
    }
}


$page = new CIndex("", $g['tmpl']['dir_tmpl_main'] . "join.html");
$header = new CHeader("header", $g['tmpl']['dir_tmpl_main'] . "_header.html");
$page->add($header);
$footer = new CFooter("footer", $g['tmpl']['dir_tmpl_main'] . "_footer.html");
$page->add($footer);

$register = new CJoinForm("join", null);
$page->add($register);

include("./_include/core/main_close.php");
Avatar billede rax Praktikant
03. marts 2008 - 13:02 #1
hvilket tegnsæt anvender du? Og hvilke tegn understøtter du i den bagvedliggende database?

Du bør anvende ISO-8859-1 tegnsættet, hvis du gerne vil behandle danske tegn. Prøv at føje denne linie til i dit <head> tag:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

og vend tilbage, hvis du fortsat har problemer :)
Avatar billede maddoggy Nybegynder
03. marts 2008 - 13:49 #2
Hej, rax

tak, for svaret.

Det var ikke det der skulle til desværre.

Jeg benytter UTF-8 og i database er den sat til utf-8 unicode.ci og prøvet med danish.ci uden held.

Selve siden godtager fint æøå men ikke ved tilmelding, så jeg fatter det bare ikke :-(

Kan det være at man skal have noget ala dette flettet ind et sted som jeg bare ikke lige kan se hvor den skal placeres?

if (!preg_match("/^[-0-9A-Z_@\sæøåÆØÅ]+
Avatar billede jakobdo Ekspert
03. marts 2008 - 21:30 #3
Hvordan ser din to_sql() ud ?
Avatar billede maddoggy Nybegynder
04. marts 2008 - 08:24 #4
den ser således ud:

if (DB::result("SELECT user_id FROM user WHERE name=" . to_sql($name, "Text") . ";") != "")
        {
            $this->message .= $l['join.php']['exists_username'] . "<br>";
Avatar billede jakobdo Ekspert
05. marts 2008 - 08:40 #5
Nej, jeg mener hvordan ser din funktion: to_sql() ud ?
Avatar billede maddoggy Nybegynder
05. marts 2008 - 09:00 #6
ahh, så må det være denne :-)

function add_user()
    {
        $partner = (int) get_session("partner");
        global $g;
        DB::execute("
            UPDATE partner SET
            account=(account+" . to_sql($g['options']['partner_price_user'], "Number") . "),
            summary=(summary+" . to_sql($g['options']['partner_price_user'], "Number") . "),
            count_users=(count_users+1)
            WHERE partner_id=" . $partner . "
        ");

        $p_partner = DB::result("SELECT p_partner FROM partner WHERE partner_id=" . $partner . "");

        $plus = ($g['options']['partner_percent_ref'] / 100) * $g['options']['partner_price_user'];
        DB::execute("
            UPDATE partner SET
            account=(account+" . $plus . "),
            summary=(summary+" . $plus . ")
            WHERE partner_id='" . $p_partner . "'
        ");

        $tosql = "";
        foreach ($g['user_var'] as $k => $v)
        {
            if (substr($k, 0, 2) != "p_")
            {
                if ($v[0] == "textarea")
                {
                    $tosql .= $k . "='', ";
                }
            }
        }
        $tosql = substr($tosql, 0, strlen($tosql) - 2);
       
        $country = DB::result("SELECT country_title FROM geo_country WHERE country_id=" . to_sql(get_session("j_country"), "Number") . "");

        DB::execute("INSERT INTO email SET mail=" . to_sql(get_session("j_mail"), "Text") . "");
        DB::execute("
            INSERT INTO user
            SET
            partner=" . $partner . ",
            gold_days=0,
            name=" . to_sql(get_session("j_name"), "Text") . ",
            orientation=" . to_sql(get_session("j_orientation"), "Number") . ",
            p_orientation=" . to_sql(DB::result("SELECT search FROM const_orientation WHERE id=" . to_sql(get_session("j_orientation"), "Number")), "Number") . ",
            gender=" . to_sql(DB::result("SELECT gender FROM const_orientation WHERE id=" . to_sql(get_session("j_orientation"), "Number")), "Text") . ",
            mail=" . to_sql(get_session("j_mail"), "Text") . ",
            password=" . to_sql($g['options']['md5'] == "Y" ? md5(get_session("j_password")) : get_session("j_password"), "Text") . ",
            country_id=" . to_sql(get_session("j_country"), "Number") . ",
            country=" . to_sql($country, "Text") . ",
            birth=" . to_sql(get_session("j_year") . "-" . get_session("j_month") . "-" .  get_session("j_day"), "Text") . ",
            horoscope=" . to_sql(zodiac(get_session("j_year") . "-" . get_session("j_month") . "-" .  get_session("j_day")), "Number") . ",
            p_horoscope=0,
            active='Y',
            active_code='',
            hide_time='0',
            register='" . date('Y-m-d H:i:s') . "',
            last_visit='" . date('Y-m-d H:i:s') . "',
            last_ip='',
            set_email_mail='2',
            set_email_interest='2'
        ");

        global $user_id;
        $user_id = DB::insert_id();

        DB::execute("
            INSERT INTO userinfo
            SET
            user_id=" . $user_id . ",
            " . $tosql . "
        ");

        DB::execute("
            INSERT INTO userpartner
            SET
            user_id=" . $user_id . "
        ");

        DB::execute("DELETE FROM zforum_users WHERE id=".$user_id.";");
        DB::execute("
            INSERT INTO zforum_users
            (id,username, group_id, password, email, email_setting, save_pass, registered)
            VALUES(".
            $user_id.",".
            to_sql(get_session("j_name"), "Text").
            ", 4, ".
            to_sql(get_session("j_password"), "Text").
            ", ".
            to_sql(get_session("j_mail"), "Text").
            ", 1 , 1 ,1".
            ");"
        );

        $subject = DB::result("SELECT subject FROM email_auto WHERE note='join'");
        $text = DB::result("SELECT text FROM email_auto WHERE note='join'");
        $subject = str_replace("{title}", $g['main']['title'], $subject);
        $text = str_replace("{title}", $g['main']['title'], $text);
        $text = str_replace("{name}", get_session("j_name"), $text);
        $text = str_replace("{password}", get_session("j_password"), $text);
        send_mail(
            get_session("j_mail"),
            $g['main']['info_mail'],
            $subject,
            $text
        );
       
        #session_unset();
        set_session("user_id", $user_id);
        set_session("user_id_verify", $user_id);
    }
}


$page = new CJoin3("", $g['tmpl']['dir_tmpl_main'] . "join_space.html");
Avatar billede jakobdo Ekspert
05. marts 2008 - 09:33 #7
Jamen for H...... da....
Jeg spørger til at se funktionen: to_sql() og du giver mig add_user().
Er det mig som ikke udtrykker mig korrekt? :o)
Avatar billede maddoggy Nybegynder
05. marts 2008 - 10:08 #8
jeg tror du udtrykker dig fint, bare ikke så jeg fatter det :-)
må desværre give fortabt da jeg ikke har nogen funktion der "bare" hedder to_sql()
Udover det der allerede er skrevet ind, her i tråden så har jeg flere ala det samme og en connect til datebasen hvis det ikke kan bruges må jeg lukke tråden og lade det være det, trals.
Avatar billede jakobdo Ekspert
05. marts 2008 - 10:14 #9
Hvad sker der hvis du prøver at oprette brugeren: blåbærgrød ?
Avatar billede maddoggy Nybegynder
05. marts 2008 - 10:19 #10
der kommer der denne fejl: brugernavn may only contain alphanumeric characters
Avatar billede jakobdo Ekspert
05. marts 2008 - 10:31 #11
Jeg tror desværre der er kode som ikke bliver vist.
Du har en eller anden kontrol, som tjekker brugernavnet, og som jeg ser det, så er den ikke blevet vist endnu.
Prøv at kig din kode igennem for preg eller ereg eller måske ctype_alphanum.
Avatar billede maddoggy Nybegynder
05. marts 2008 - 10:45 #12
kan det ligge heri ? (var et php doku med en hulens masse function)

// Equivalent to htmlspecialchars(), but allows &#[0-9]+ (for unicode)
//
function pun_htmlspecialchars($str)
{
    $str = preg_replace('/&(?!#[0-9]+;)/s', '&', $str);
    $str = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $str);

    return $str;
}

også bare tilføje $str = preg_replace('/&(?!#[0-9æøåÆØÅ]+;)/s', '&', $str);

El. skal der mere med det er jeg ikke så stærk i?
Avatar billede jakobdo Ekspert
05. marts 2008 - 10:52 #13
Nej, det er heller ikke det. :o)
Avatar billede maddoggy Nybegynder
05. marts 2008 - 10:53 #14
ok, kikker videre :-) tak for hjælpen indtil videre.
Avatar billede maddoggy Nybegynder
05. marts 2008 - 18:02 #15
har fundet denne JS fil hvor i der valideres på brugernavn, er der nogen speciel måde at tillade æøå i java script?

var MSG_MAX_LENGTH            = '%1 may only be a maximum of %2 characters long.';
var MSG_MIN_LENGTH            = '%1 must be a minimum of %2 characters long.';
var MSG_REQ_FIELD          = '%1 is a required field.';
var MSG_INVALID_EMAIL      = 'Invalid email address: %1';
var MSG_REQUIRED_SELECT        = 'Please select a value for %1.';
var MSG_ALPHA_NUMERIC        = '%1 may only contain alphanumeric characters.';
var MSG_NUMERIC            = '%1 may only contain numeric characters!';
var MSG_TWO_FIELDS            = '%1 and %2 must be the same.';
var MSG_NOT_TWO_FIELDS      = '%1 and %2 may not have the same value.';


function validateMaxLength(field, name, maxLength) {
    var value = field.value;
    var originalVal = value;    //store a copy with the \n's in it
    var newVal = "";    //new value with any extra characters removed from it so as not to go over maxLength
    var character = null;
    value = value.replace(/\n/g,'**'); // bug #4830 when the javascript validates it sees \n's and java validates it sees \r\n's so a string may pass javascript validation but fail java validation, solution validate on a copy of the string with all \n's replaced with 2 characters to simulate the java length

    if (value.length > maxLength)
    {
        //loop through the string getting one character at a time.
        //If we encounter a \n we have to count it as 2 characters due to bug #4830
        for(var i=0, count=1; count<=maxLength; i++, count++){
                character = originalVal.charAt(i);

                //if this is a new line char make sure we have 2 spaces available in the new string
                if(character == "\n" && count<=maxLength-1){
                    newVal = newVal.concat(character);
                    count++;
                }else{
                    newVal = newVal.concat(character);
                }
        }

        var msg = MSG_MAX_LENGTH.replace('%1', name);
        msg = msg.replace('%2', maxLength);
        alert(msg);
        try{
            //substitute in the shortened string into the field.
            field.value = newVal;
            field.focus();
        }catch(e){}
        return false;
    }
    return true;
}
function validateMinLength(field, name, minLength) {
    if (field.value.length < minLength) {
        var msg = MSG_MIN_LENGTH.replace('%1', name);
        msg = msg.replace('%2', minLength);
        alert(msg);
        try{field.focus();}catch(e){}
        return false;
    }
    else {
        return true;
    }
}
function nonEmptyDependency(field1, field1Name, field2, field2Name, message) {
    if(!isEmpty(field1) && isEmpty(field2)){
        alert(message);
        return false;
    }else{
        return true;
    }
}
function validateRequiredField(field, name, dv) {
    try
    {
        field.value = field.value.trim();
        dv = dv.trim();
    }
    catch(e) {}

    if (field.value.length == 0 || field.value == dv)
    {
        alert(MSG_REQ_FIELD.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateEmailField(emailField, name) {
    if (isEmpty(emailField)) return true;
    if (!checkEmail(emailField.value)) {
        alert(MSG_INVALID_EMAIL.replace('%1', emailField.value));
        try{emailField.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateRequiredCheckbox(field, name, msg) {
    if (!isCheckBoxChecked(field)) {
        alert(msg.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateRequiredSelect(field, name, defaultValue) {
    if (field.value == null || field.value == '' || field.value == defaultValue) {
        alert(MSG_REQUIRED_SELECT.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    else {
        return true;
    }
}
function validateTwoFields(field,name,field2,name2) {
    if (field.value != field2.value){
        var msg = MSG_TWO_FIELDS.replace('%1', name);
        msg = msg.replace('%2', name2);
        alert(msg);
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateNotTwoFields(field,name,field2,name2) {
    if (field.value == field2.value){
        var msg = MSG_NOT_TWO_FIELDS.replace('%1', name);
        msg = msg.replace('%2', name2);
        alert(msg);
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateAlphaNumeric(field, name) {
    var mask = /^[_0-9a-zA-Z-\.]*[_0-9a-zA-Z-\.]$/
    if (!mask.test(field.value)) {
        alert(MSG_ALPHA_NUMERIC.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateAlphaNumeric_search(field, name) {
    var mask = /^[_0-9a-zA-Z-\.\s]*[_0-9a-zA-Z-\.\s]$/
    if (!mask.test(field.value)) {
        alert(MSG_ALPHA_NUMERIC.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateNumeric(field, name) {
    var val = trim(field.value);
    field.value = val;
    var mask = /^-?[0-9]*(\.)?[0-9]*$/
    if (!mask.test(val)) {
        alert(MSG_NUMERIC.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}



function isEmpty(field) {
    if (field.disabled){return true;}

    if (field.type=='checkbox'||(field[0]&&field[0].type == 'checkbox')) {
        return !isCheckBoxChecked(field);
    }
    if (field.type=='radio'||(field[0]&&field[0].type == 'radio')) {
        return !isCheckBoxChecked(field);
    }
    //Try trim - will fail for input type="file".
    try
    {
        field.value = field.value.trim();
    }
    catch(e) {}
    if (field.value.length == 0) {
        return true;
    }
}
function isCheckBoxChecked(field) {
    if (field[0]) {
        for (i = 0;i<field.length;i++) {
            theField = field[i];
            if (theField.checked) {
                return true;
            }
        }
        return false;
    } else {
        if (!field.checked) {
            return false;
        }
    }
    return true;
}
function setFocus(form,field) {
    if (form != '') {
        try    {document.forms[form][field].focus();} catch(e) {}
    }
    else {
        try    {document.forms[0][field].focus();} catch(e) {}
    }
}
function giveFocus(frm, elm) {
  eval("document."+frm+"."+elm+".focus()");
}
function winpop(loc,w,h,scroll) {
    var name = loc.replace(/\W/g, "");
    window.open(loc,name,'width='+w+', height='+h+', location=no, directories=no, menubar=no, scrollbars='+scroll+', resizable=no, status=no, toolbar=no');
}

function getById(tag) {
  if (document.getElementById) //  Netscape, Mozilla, etc.
  {
    return document.getElementById(tag);
  }
  else if (document.all)      //  IE, Konqueror, etc.
  {
    return document.all[tag];
  }
}
function switchdiv(div1_id, div2_id, form) {
    if (document.getElementById)    {
        if(!document.getElementById(div1_id)) return ;
        if(!(document.getElementById(div1_id).style)) return ;
        if(!(document.getElementById(div1_id).style.display)) return ;

        var state1 = document.getElementById(div1_id).style.display;
        if(state1=="none") {
                document.getElementById(div1_id).style.display="block";
                document.getElementById(div2_id).style.display="none";
                if (form != null)
                {
                  form[div1_id].value='true';
                  form[div2_id].value='false';
                }
        }
        if(state1=="block") {
                document.getElementById(div2_id).style.display="block";
                document.getElementById(div1_id).style.display="none";
                if (form != null)
                {
                  form[div1_id].value='false';
                  form[div2_id].value='true';
                }
        }
    }
    else if (document.all)    {
        if(!document.all[div1_id]) return ;
        if(!(document.all[div1_id].style)) return ;
        if(!(document.all[div1_id].style.display)) return ;

        var state1 = document.all[div1_id].style.display;
        if(state1=="none") {
                document.all[div1_id].style.display = "block";
                document.all[div2_id].style.display = "none";
                if (form != null)
                {
                  form[div1_id].value='true';
                  form[div2_id].value='false';
                }
        }
        if(state1=="block") {
                document.getElementById(div1_id).style.display="none";
                document.getElementById(div2_id).style.display="block";
                if (form != null)
                {
                  form[div1_id].value='false';
                  form[div2_id].value='true';
                }
        }
    }
}
function getRefToDiv(divID) {
    if( document.layers ) { //Netscape layers
        return document.layers[divID]; }
    if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); }
    if( document.all ) { //Proprietary DOM; IE4
        return document.all[divID]; }
    if( document[divID] ) { //Netscape alternative
        return document[divID]; }
    return false;
}
function characterCounter(fieldName, maxLength, elementName) {
    var field = getById(fieldName);
    var value = field.value.replace(/\n/g,'**'); // bug #4830 when the javascript validates it sees \n's and java validates it sees \r\n's so a string may pass javascript validation but fail java validation, solution validate on a copy of the string with all \n's replaced with 2 characters to simulate the java length
    getById(elementName).innerHTML = value.length;
}
function trim(str) {
    str = new String(str);
    return str.replace(/^\s+/,'').replace(/\s+$/,'');
}
function submitForm(form, action) {
    form.action = action;
    form.submit();
}
var gOnload = new Array();
function addOnload(f) {

    if (window.onload)
    {
        if (window.onload != runOnload)
        {
            gOnload[0] = window.onload;
            window.onload = runOnload;
        }
        gOnload[gOnload.length] = f;
    }
    else
        window.onload = f;
}
function runOnload() {
    for (var i=0;i<gOnload.length;i++)
        gOnload[i]();
}
function checkEmail(emailStr) {
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]!%";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) {
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];
    for (i=0; i<user.length; i++) {
        if (user.charCodeAt(i)>127) {
            return false;
        }
    }
    for (i=0; i<domain.length; i++) {
        if (domain.charCodeAt(i)>127) {
            return false;
        }
    }
    if (user.match(userPat)==null) {
        return false;
    }

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                return false;
            }
        }
        return true;
    }

    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
        if (domArr[i].search(atomPat)==-1) {
            return false;
        }
    }
    if (domArr[len-1].length < 2) {
        return false;
    }
    if (len<2) {
        return false;
    }
    /*mask=/^(root|abuse|webmaster|help|postmaster|sales|resumes|contact|advertising|spam|spamtrap|nospam|noc|admin|support|daemon|listserve|listserver|autoreply)@/i;
    if (mask.test(emailStr.toLowerCase())) {
        return false;
    }*/

    return true;
}
function updateDay(change,formName,yearName,monthName,dayName)
{
    var form = document.forms[formName];
    var yearSelect = form[yearName];
    var monthSelect = form[monthName];
    var daySelect = form[dayName];
    var year = yearSelect[yearSelect.selectedIndex].value;
    var month = monthSelect[monthSelect.selectedIndex].value;
    var day = daySelect[daySelect.selectedIndex].value;

    if (change == 'month' || (change == 'year' && month == 2))
    {
        var i = 31;
        var flag = true;
        while(flag)
        {
            var date = new Date(year,month-1,i);
            if (date.getMonth() == month - 1)
            {
                flag = false;
            }
            else
            {
                i = i - 1;
            }
        }

        daySelect.length = 0;
        daySelect.length = i;
        var j = 0;
        while(j < i)
        {
            daySelect[j] = new Option(j+1,j+1);
            j = j + 1;
        }
        if (day <= i)
        {
            daySelect.selectedIndex = day - 1;
        }
        else
        {
            daySelect.selectedIndex = daySelect.length - 1;
        }
    }
}
function checkedCount(field) {
    var    checked    = 0;

    if (field != null) {
        if (field.length == null)
        {
            if (field.checked == true)
            {
                checked++;
            }
        }
        else
        {
            for    (var i = 0 ; i < field.length    ; i++)
            {
                if (field[i].checked == true)
                {
                    checked++;
                }
            }
        }
    }

    return checked;
}
function isChecked(field) {
    if (checkedCount(field) == 0)
    {
        return false;
    }
    return true;
}
function isOneChecked(field) {
    if (checkedCount(field) == 1)
    {
        return true;
    }
    return false;
}
Avatar billede maddoggy Nybegynder
05. marts 2008 - 18:03 #16
og de 2 jeg regner med der er tale om er disse:

function validateAlphaNumeric(field, name) {
    var mask = /^[_0-9a-zA-Z-\.]*[_0-9a-zA-Z-\.]$/
    if (!mask.test(field.value)) {
        alert(MSG_ALPHA_NUMERIC.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
}
function validateAlphaNumeric_search(field, name) {
    var mask = /^[_0-9a-zA-Z-\.\s]*[_0-9a-zA-Z-\.\s]$/
    if (!mask.test(field.value)) {
        alert(MSG_ALPHA_NUMERIC.replace('%1', name));
        try{field.focus();}catch(e){}
        return false;
    }
    return true;
Avatar billede jakobdo Ekspert
05. marts 2008 - 18:15 #17
Jeg tror netop det et i linjerne: var mask = /^[_0-9a-zA-Z-\.]*[_0-9a-zA-Z-\.]$/
Der skal tilføjes ÆØÅ og æøå
Avatar billede maddoggy Nybegynder
05. marts 2008 - 18:50 #18
nogen ide til hvorledes det skal se ud da der bare meldes script error hvis det sættes efter som dette:

/^[_0-9a-zA-ZæøåÆØÅ-\.]*[_0-9a-zA-ZæøåÆØÅ-\.]$/
Avatar billede jakobdo Ekspert
05. marts 2008 - 21:13 #19
Jeg ved ikke om MASK er et javascript api du bruger.
Men der burde være noget javascript bagved i stil med match().
Kan du finder ud af det nogen steder?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester