21 Eylül 2018 Cuma

JS Validation

@model WebTimeSheetManagement.Models.Registration
@using CaptchaMvc.HtmlHelpers
@{
    ViewBag.Title = "CreateAdmin";
    Layout = "~/Views/Shared/_LayoutSuperAdmin.cshtml";
}

<h4 class="page-header">Create Admin User</h4>

    <div class="panel panel-default">
        <div class="panel-heading">Create Admin User</div>
        <div class="panel-body">

            @if (TempData["MessageRegistration"] != null)
            {
                <p class="alert alert-success" id="successMessage">@TempData["MessageRegistration"]</p>
            }

            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

            @using (Html.BeginForm("CreateAdmin", "SuperAdmin"))
            {
                @Html.AntiForgeryToken()

                <div class="row">
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.TextBoxFor(model => model.Name, new { @class = "form-control", @maxlength = 40, @onkeypress = "return onlyspecchar(event);" })
                        @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                    </div>
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.Mobileno, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.TextBoxFor(model => model.Mobileno, new { @class = "form-control", @maxlength = 10, @onkeydown = "return OnlyNumeric(this);" })
                        @Html.ValidationMessageFor(model => model.Mobileno, "", new { @class = "text-danger" })
                    </div>
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.EmailID, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.TextBoxFor(model => model.EmailID, new { @class = "form-control", @maxlength = 50 })
                        @Html.ValidationMessageFor(model => model.EmailID, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4" style="margin-top:20px;">
                        @Html.LabelFor(model => model.Gender, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.RadioButtonFor(model => model.Gender, "M") @Html.Label("", "Male")
                        @Html.RadioButtonFor(model => model.Gender, "F") @Html.Label("", "Female")
                        <br />
                        @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "text-danger" })
                    </div>
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.Birthdate, htmlAttributes: new { @class = "control-label" })
                        @Html.TextBoxFor(model => model.Birthdate, new { @class = "form-control", @onkeypress = "alert('Choose Birthdate');" })
                        @Html.ValidationMessageFor(model => model.Birthdate, "", new { @class = "text-danger" })
                    </div>
                    <div class="col-lg-4">
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.Username, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.TextBoxFor(model => model.Username, new { @class = "form-control", @maxlength = 20, @onkeypress = "return onlyspecchar(event);", @onblur = "CheckUsernameExists();" })
                        @Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
                    </div>
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.PasswordFor(model => model.Password, new { @class = "form-control", @maxlength = 30, })
                        @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
                    </div>
                    <div class="col-lg-4">
                        @Html.LabelFor(model => model.ConfirmPassword, htmlAttributes: new { @class = "control-label manadatory" })
                        @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
                    </div>
                </div>
     <br />
                <div class="row">
                    <div class="form-group">
                        <div class="col-md-10">
                            <input type="submit" value="Create Admin" class="btn btn-success" />
                            @Html.ActionLink("Clear", "CreateAdmin", "SuperAdmin", null, new { @class = "btn btn-danger" })

                            @Html.ActionLink("All Admin", "admin", "AllUsers", null, new { @class = "btn btn-info" })
                         
                        </div>
                    </div>
                </div>
            }

        </div>
    </div>



<script type="text/javascript">

    $(document).ready(function () {
        $("#Birthdate").datepicker
            ({
                dateFormat: "yy-mm-dd",
                changeMonth: true,
                changeYear: true,
                yearRange: "-100:+100",
                onSelect: function (date) {
                    var dob = new Date(date);
                    var today = new Date();

                    if (dob.getFullYear() + 18 < today.getFullYear()) {

                    }
                    else {
                        $("#Birthdate").val('');
                        alert("You are not eligible for Registration");
                    }
                }
            });
    });

    function OnlyNumeric(evt) {
        var charCode = (evt.which) ? evt.which : evt.keyCode
        if ((charCode < 48 || charCode > 57)) {
            if (charCode == 8 || charCode == 46 || charCode == 0) {
                return true;
            }
            else {
                return false;
            }
        }
    }

    function CheckUsernameExists() {
        var url = '@Url.Content("~/")' + "Registration/CheckUserNameExists";
        var source = "#Username";
        $.post(url, { Username: $(source).val() }, function (data) {
            if (data) {
                $(source).val('');
                alert("Username Already Used try unique one!");
            }
            else {

            }
        });
    }

    function onlyspecchar(evt) {
        var charCode = (evt.which) ? evt.which : evt.keyCode
        var txt = String.fromCharCode(charCode)
        if ((txt.match(/^[a-zA-Z\b. ]+$/)) || (txt.match(/^[0-9]+$/)) || (charCode == 64) || (charCode == 45) || (charCode == 46) || (charCode == 95) || (charCode == 41)) {
            return true;
        }
        return false;
    }
</script>

Hiç yorum yok:

Yorum Gönder

evren pehlivan yazılım

evren pehlivan yazılım, evren pehlivan yazılım geliştirici