Back to feed
Renewal·서른의 생활코딩

Sample source 3) JavaScript basic document structure (string object)

NS
normalstory
cover image

This time let's look at the string object.
A string is a sequence of characters.
In other words, by using the string object and the methods it owns,
you can program with strings.

For instance, when a user has written an email, 
you could check in advance whether they wrote it correctly,
or — if you do more detailed and meticulous work — even something like spell-checking should be plenty possible.
(Whether useful or not...)




<!DOCTYPE html>


<html>


<head>


<meta charset="utf-8" />


<title>string object</title>


<script type="text/javascript">


//<![CDATA[




//string has the length property and the indexOf / lastIndexOf methods.




var str1, str2;


str1 = new String("javascript");


str2 = "DOMScript";




document.write("<p>" + str1.length + "</p>");


document.write("<p>" + str2.length + "</p>");


document.write("<p>" + str1.indexOf("s") + "</p>");




var email="testtest.co.kr";


var check=email.indexOf("@");// returns -1 if not present. !!!




if(check == -1)


{


alert("The email format is not valid.");


}




//]]]]>


</script>


</head>




<body>




</body>


</html>

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Why You Should Use .html Instead of .md Seeing Is Believing

Jul 25, 2026·1 min
Renewal

The Most Important Thing About AX

Jul 17, 2026·2 min
Renewal

디지털 기술과 혁신에 대한 논고(지탱하는 힘)

Jul 17, 2026·5 min