Candidate registration, with validation, using MVVM

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite
1












I am new to MVVM. I Created Model class CandidateRegisterModel and ViewModel class CandidateRegisterViewModel



class CandidateRegisterModel: NSObject 
let viewModel = CandidateRegisterViewModel.self
var candidateName : String
var email : String
var mobileNo: Int
var skill : String
var location : String
var totalExp : Int
var designation : String
var industry : String
var uploadResume : String

init(candidateName: String, email: String, mobileNo: Int, skill: String, location: String, totalExp: Int, designation: String, industry: String , uploadResume: String)

self.candidateName = candidateName;
self.email = email;
self.mobileNo = mobileNo;
self.skill = skill;
self.location = location;
self.totalExp = totalExp;
self.designation = designation;
self.industry = industry;
self.uploadResume = uploadResume;



class CandidateRegisterViewModel
var CandidateRegisterData = CandidateRegisterModel?.self
var candidateName : String = ""
var email : String = ""
var mobileNo: Int? = nil
var skill : String = ""
var location : String = ""
var totalExp : Int? = nil
var designation : String = ""
var industry : String = ""
var uploadResume : String = ""
private var errors: [String] =
private weak var context: UIViewController?

init(controller: UIViewController)
context = controller


init(CandidateRegisterDataa : CandidateRegisterModel)
candidateName = CandidateRegisterDataa.candidateName
email = CandidateRegisterDataa.email
mobileNo = CandidateRegisterDataa.mobileNo
skill = CandidateRegisterDataa.skill
location = CandidateRegisterDataa.location
totalExp = CandidateRegisterDataa.totalExp
designation = CandidateRegisterDataa.designation
industry = CandidateRegisterDataa.industry
uploadResume = CandidateRegisterDataa.uploadResume

func checkCandidateNameErrors(name:String) -> Bool
let RegEx = "\A\w7,18\z"
let validator = NSPredicate(format:"SELF MATCHES %@", RegEx)
let valid = validator.evaluate(with: candidateName)
if !valid
errors.append("Invalid UserName")

return valid

func checkEmailErrors(email: String) -> Bool
let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]2,4"
let validator = NSPredicate(format: "SELF MATCHES %@", regex)
let valid = validator.evaluate(with: email);
if !valid
errors.append("Invalid Email")

return valid

func checkPhoneErrors(phoneNumber: String) -> Bool
let PHONE_REGEX = "^09[0-9'@s]9,9$"
let validator = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
let valid = validator.evaluate(with: mobileNo)

if !valid
errors.append("Invalid Password")

return valid



func checkPasswordErrors(password: String) -> Bool
let valid = !password.isEmpty && password.count >= 6
if !valid
errors.append("Invalid Password")

return valid

func cleanErrors()
errors.removeAll()

func showErrors()
let message = errors.joined(separator: ("n"))
let errorAlert = UIAlertController(title: "Erros", message: message, preferredStyle: .alert)
errorAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
context?.present(errorAlert, animated: true, completion: nil)



extension CandidateRegisterViewModel
func login_model( candidateName : String, email: String, password: String, mobileNo: String)







share|improve this question

















  • 2




    Hey, welcome to Code Review! You should add some description of what your code actually accomplishes. This should also be reflected in your title. Have a look at our help-center for some more tips on how to ask a good question here.
    – Graipher
    Jul 16 at 11:36











  • The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see How do I ask a good question? for examples, and revise the title accordingly.
    – Martin R
    Jul 16 at 12:24

















up vote
0
down vote

favorite
1












I am new to MVVM. I Created Model class CandidateRegisterModel and ViewModel class CandidateRegisterViewModel



class CandidateRegisterModel: NSObject 
let viewModel = CandidateRegisterViewModel.self
var candidateName : String
var email : String
var mobileNo: Int
var skill : String
var location : String
var totalExp : Int
var designation : String
var industry : String
var uploadResume : String

init(candidateName: String, email: String, mobileNo: Int, skill: String, location: String, totalExp: Int, designation: String, industry: String , uploadResume: String)

self.candidateName = candidateName;
self.email = email;
self.mobileNo = mobileNo;
self.skill = skill;
self.location = location;
self.totalExp = totalExp;
self.designation = designation;
self.industry = industry;
self.uploadResume = uploadResume;



class CandidateRegisterViewModel
var CandidateRegisterData = CandidateRegisterModel?.self
var candidateName : String = ""
var email : String = ""
var mobileNo: Int? = nil
var skill : String = ""
var location : String = ""
var totalExp : Int? = nil
var designation : String = ""
var industry : String = ""
var uploadResume : String = ""
private var errors: [String] =
private weak var context: UIViewController?

init(controller: UIViewController)
context = controller


init(CandidateRegisterDataa : CandidateRegisterModel)
candidateName = CandidateRegisterDataa.candidateName
email = CandidateRegisterDataa.email
mobileNo = CandidateRegisterDataa.mobileNo
skill = CandidateRegisterDataa.skill
location = CandidateRegisterDataa.location
totalExp = CandidateRegisterDataa.totalExp
designation = CandidateRegisterDataa.designation
industry = CandidateRegisterDataa.industry
uploadResume = CandidateRegisterDataa.uploadResume

func checkCandidateNameErrors(name:String) -> Bool
let RegEx = "\A\w7,18\z"
let validator = NSPredicate(format:"SELF MATCHES %@", RegEx)
let valid = validator.evaluate(with: candidateName)
if !valid
errors.append("Invalid UserName")

return valid

func checkEmailErrors(email: String) -> Bool
let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]2,4"
let validator = NSPredicate(format: "SELF MATCHES %@", regex)
let valid = validator.evaluate(with: email);
if !valid
errors.append("Invalid Email")

return valid

func checkPhoneErrors(phoneNumber: String) -> Bool
let PHONE_REGEX = "^09[0-9'@s]9,9$"
let validator = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
let valid = validator.evaluate(with: mobileNo)

if !valid
errors.append("Invalid Password")

return valid



func checkPasswordErrors(password: String) -> Bool
let valid = !password.isEmpty && password.count >= 6
if !valid
errors.append("Invalid Password")

return valid

func cleanErrors()
errors.removeAll()

func showErrors()
let message = errors.joined(separator: ("n"))
let errorAlert = UIAlertController(title: "Erros", message: message, preferredStyle: .alert)
errorAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
context?.present(errorAlert, animated: true, completion: nil)



extension CandidateRegisterViewModel
func login_model( candidateName : String, email: String, password: String, mobileNo: String)







share|improve this question

















  • 2




    Hey, welcome to Code Review! You should add some description of what your code actually accomplishes. This should also be reflected in your title. Have a look at our help-center for some more tips on how to ask a good question here.
    – Graipher
    Jul 16 at 11:36











  • The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see How do I ask a good question? for examples, and revise the title accordingly.
    – Martin R
    Jul 16 at 12:24













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I am new to MVVM. I Created Model class CandidateRegisterModel and ViewModel class CandidateRegisterViewModel



class CandidateRegisterModel: NSObject 
let viewModel = CandidateRegisterViewModel.self
var candidateName : String
var email : String
var mobileNo: Int
var skill : String
var location : String
var totalExp : Int
var designation : String
var industry : String
var uploadResume : String

init(candidateName: String, email: String, mobileNo: Int, skill: String, location: String, totalExp: Int, designation: String, industry: String , uploadResume: String)

self.candidateName = candidateName;
self.email = email;
self.mobileNo = mobileNo;
self.skill = skill;
self.location = location;
self.totalExp = totalExp;
self.designation = designation;
self.industry = industry;
self.uploadResume = uploadResume;



class CandidateRegisterViewModel
var CandidateRegisterData = CandidateRegisterModel?.self
var candidateName : String = ""
var email : String = ""
var mobileNo: Int? = nil
var skill : String = ""
var location : String = ""
var totalExp : Int? = nil
var designation : String = ""
var industry : String = ""
var uploadResume : String = ""
private var errors: [String] =
private weak var context: UIViewController?

init(controller: UIViewController)
context = controller


init(CandidateRegisterDataa : CandidateRegisterModel)
candidateName = CandidateRegisterDataa.candidateName
email = CandidateRegisterDataa.email
mobileNo = CandidateRegisterDataa.mobileNo
skill = CandidateRegisterDataa.skill
location = CandidateRegisterDataa.location
totalExp = CandidateRegisterDataa.totalExp
designation = CandidateRegisterDataa.designation
industry = CandidateRegisterDataa.industry
uploadResume = CandidateRegisterDataa.uploadResume

func checkCandidateNameErrors(name:String) -> Bool
let RegEx = "\A\w7,18\z"
let validator = NSPredicate(format:"SELF MATCHES %@", RegEx)
let valid = validator.evaluate(with: candidateName)
if !valid
errors.append("Invalid UserName")

return valid

func checkEmailErrors(email: String) -> Bool
let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]2,4"
let validator = NSPredicate(format: "SELF MATCHES %@", regex)
let valid = validator.evaluate(with: email);
if !valid
errors.append("Invalid Email")

return valid

func checkPhoneErrors(phoneNumber: String) -> Bool
let PHONE_REGEX = "^09[0-9'@s]9,9$"
let validator = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
let valid = validator.evaluate(with: mobileNo)

if !valid
errors.append("Invalid Password")

return valid



func checkPasswordErrors(password: String) -> Bool
let valid = !password.isEmpty && password.count >= 6
if !valid
errors.append("Invalid Password")

return valid

func cleanErrors()
errors.removeAll()

func showErrors()
let message = errors.joined(separator: ("n"))
let errorAlert = UIAlertController(title: "Erros", message: message, preferredStyle: .alert)
errorAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
context?.present(errorAlert, animated: true, completion: nil)



extension CandidateRegisterViewModel
func login_model( candidateName : String, email: String, password: String, mobileNo: String)







share|improve this question













I am new to MVVM. I Created Model class CandidateRegisterModel and ViewModel class CandidateRegisterViewModel



class CandidateRegisterModel: NSObject 
let viewModel = CandidateRegisterViewModel.self
var candidateName : String
var email : String
var mobileNo: Int
var skill : String
var location : String
var totalExp : Int
var designation : String
var industry : String
var uploadResume : String

init(candidateName: String, email: String, mobileNo: Int, skill: String, location: String, totalExp: Int, designation: String, industry: String , uploadResume: String)

self.candidateName = candidateName;
self.email = email;
self.mobileNo = mobileNo;
self.skill = skill;
self.location = location;
self.totalExp = totalExp;
self.designation = designation;
self.industry = industry;
self.uploadResume = uploadResume;



class CandidateRegisterViewModel
var CandidateRegisterData = CandidateRegisterModel?.self
var candidateName : String = ""
var email : String = ""
var mobileNo: Int? = nil
var skill : String = ""
var location : String = ""
var totalExp : Int? = nil
var designation : String = ""
var industry : String = ""
var uploadResume : String = ""
private var errors: [String] =
private weak var context: UIViewController?

init(controller: UIViewController)
context = controller


init(CandidateRegisterDataa : CandidateRegisterModel)
candidateName = CandidateRegisterDataa.candidateName
email = CandidateRegisterDataa.email
mobileNo = CandidateRegisterDataa.mobileNo
skill = CandidateRegisterDataa.skill
location = CandidateRegisterDataa.location
totalExp = CandidateRegisterDataa.totalExp
designation = CandidateRegisterDataa.designation
industry = CandidateRegisterDataa.industry
uploadResume = CandidateRegisterDataa.uploadResume

func checkCandidateNameErrors(name:String) -> Bool
let RegEx = "\A\w7,18\z"
let validator = NSPredicate(format:"SELF MATCHES %@", RegEx)
let valid = validator.evaluate(with: candidateName)
if !valid
errors.append("Invalid UserName")

return valid

func checkEmailErrors(email: String) -> Bool
let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]2,4"
let validator = NSPredicate(format: "SELF MATCHES %@", regex)
let valid = validator.evaluate(with: email);
if !valid
errors.append("Invalid Email")

return valid

func checkPhoneErrors(phoneNumber: String) -> Bool
let PHONE_REGEX = "^09[0-9'@s]9,9$"
let validator = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
let valid = validator.evaluate(with: mobileNo)

if !valid
errors.append("Invalid Password")

return valid



func checkPasswordErrors(password: String) -> Bool
let valid = !password.isEmpty && password.count >= 6
if !valid
errors.append("Invalid Password")

return valid

func cleanErrors()
errors.removeAll()

func showErrors()
let message = errors.joined(separator: ("n"))
let errorAlert = UIAlertController(title: "Erros", message: message, preferredStyle: .alert)
errorAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
context?.present(errorAlert, animated: true, completion: nil)



extension CandidateRegisterViewModel
func login_model( candidateName : String, email: String, password: String, mobileNo: String)









share|improve this question












share|improve this question




share|improve this question








edited Jul 16 at 13:30









200_success

123k14143399




123k14143399









asked Jul 16 at 11:12









Anshu

13




13







  • 2




    Hey, welcome to Code Review! You should add some description of what your code actually accomplishes. This should also be reflected in your title. Have a look at our help-center for some more tips on how to ask a good question here.
    – Graipher
    Jul 16 at 11:36











  • The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see How do I ask a good question? for examples, and revise the title accordingly.
    – Martin R
    Jul 16 at 12:24













  • 2




    Hey, welcome to Code Review! You should add some description of what your code actually accomplishes. This should also be reflected in your title. Have a look at our help-center for some more tips on how to ask a good question here.
    – Graipher
    Jul 16 at 11:36











  • The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see How do I ask a good question? for examples, and revise the title accordingly.
    – Martin R
    Jul 16 at 12:24








2




2




Hey, welcome to Code Review! You should add some description of what your code actually accomplishes. This should also be reflected in your title. Have a look at our help-center for some more tips on how to ask a good question here.
– Graipher
Jul 16 at 11:36





Hey, welcome to Code Review! You should add some description of what your code actually accomplishes. This should also be reflected in your title. Have a look at our help-center for some more tips on how to ask a good question here.
– Graipher
Jul 16 at 11:36













The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see How do I ask a good question? for examples, and revise the title accordingly.
– Martin R
Jul 16 at 12:24





The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see How do I ask a good question? for examples, and revise the title accordingly.
– Martin R
Jul 16 at 12:24
















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f199584%2fcandidate-registration-with-validation-using-mvvm%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f199584%2fcandidate-registration-with-validation-using-mvvm%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?