程序代写代做 Java javascript Functions for Form Validation

Functions for Form Validation
▪ Checking a variable is Not a Number if (isNaN(string)) { …}
▪ Convert string into a float/integer: foatValue = parseFloat(“12.34”)
intValue = parseInt(“1234”)
▪ Evaluate the result of a ‘command’ string
x=4; y=7; aCmd = “if (x < 9) { x * y } else { x / y }" document.write("Result of aCmd is " + eval(aCmd) + "
“)
▪ Works with Regular Expressions.
□ Creates a RegExp object: RegObject = /pattern/
Eg. re = /5[0-9]{7}/
□ Tests for a match in a string: test(str):
Eg, if ( re.test(stdentID) ) { … }
2

Using Regular Expression
▪ Used for complex string manipulation:
□ ^ – start with, eg ^one means any string starts with one.
□ $ – end with, eg ing$ means end with ing.
□ […] – any character within [], eg [a-zA-Z0-9] means any alphanumeric.
□ |-or,ega|bmeansaorb.
□ (…) – grouping, eg (ch|p)air means either chair or pair.
□ + – repeat 1 or more times; * – report 0 or more; ? – appear 0 or 1 time.
□ {…} – repeat times specifies within {}, eg a{2,} means start with 2 or
more a; ba{2,4}d means baad, or baaad, baaaad.
□ [^…] – anything except in [], eg [^a-zA-Z] means non-letters.
□ Other special characters: . (any char), \d (digit), \w (word), etc.
What do these patterns mean?
([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})
^(http:\/\/)?([^\/]+)\.com$
3

Form Validation

Name:

ID:


4

Javascript Date Object
▪ Date object and its methods work with dates and times.
myDate = new Date(parameters)
□ Nothing: creates today’s date and time.
Eg, today = new Date()
□ A string in the form: “month day, year hours:minutes:seconds”
Eg, Xmas07 = new Date(“December 24, 2007 20:30:00”)
□ A set of integer values for year, month, and day.
Eg, Xmax17 = new Date(2017,12, 24)
▪ Date Object’s Methods:
□ thisDate.getDate(), thisDate.getDay(), thisDate.getMonth(),
thisDate.getHours(), thisDate.getMinutes(), …
□ thisDate.setDate(dayvalue), thisDate.setMonth(monthvalue),
thisDate.setTime(msec), …
□ thisDate.toDateString(), thisDate.toTimeString(), …
5