Skip to content

Instantly share code, notes, and snippets.

View alexonozor's full-sized avatar
🏠
Working from home

Alex Onozor alexonozor

🏠
Working from home
View GitHub Profile
/** A user name can't match the given regular expression */
export function forbiddenUserNameValidator(nameRe: RegExp): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} => {
const forbidden = nameRe.test(control.value);
return forbidden ? {'forbiddenName': {value: control.value}} : null;
};
}
const userForm = new FormGroup({
userName: new FormControl('', [
Validators.required,
Validators.minLength(2),
forbiddenNameValidator(/bob/i) // <-- Here's how you pass in the custom validator.
]),
firstName: new FormControl('', [ Validators.required, Validators.minLength(2)]),
lastName: new FormControl(''),
address: new FormGroup({
street: new FormControl('', Validators.required),
this.userForm.setValue({
userName: "AlexOnozor",
firstName: "Alex",
lastName: "Obogbare"
address: { ... } // reduce for brevity
});
this.userForm.patchValue({
userName: 'alexonozor'
});
//rest the the entire form values and status.
this.userForm.reset();
//rest the user name and it status.
this.userForm.reset({
userName: ''
});
@alexonozor
alexonozor / rubycode.rb
Created April 22, 2018 15:25
Code snippet from my ruby hangman gem.
def menu
option_choice = get_input('')
case option_choice
when "1"
menu_start_game
when "2"
load
when "3"
menu_instruction
when "4", "X", "x", "Q", "q", :quit
var Engine = (function(global) {
var doc = global.document,
win = global.window,
canvas = doc.createElement('canvas'),
ctx = canvas.getContext('2d'),
lastTime;
canvas.width = 505;
canvas.height = 606;
doc.body.appendChild(canvas);